I am implementing Xamarin AppAuth library with IdentityServer4. I cannot achieve redirect after authorization in custom tab back to the application. Authorization request is shown below:
AuthorizationRequest.Builder authReqBuilder =
new AuthorizationRequest.Builder(authConfig,
"clientId",
ResponseTypeValues.Code,
Uri.Parse("https://com.example/oauth2redirect"));
authReqBuilder.SetScope("api1 openid profile offline_access");
Here is configuration in AndroidManifest.xml:
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools">
<application ...>
<activity
android:name="net.openid.appauth.RedirectUriReceiverActivity"
tools:node="replace">
<intent-filter>
<action android:name="android.intent.action.VIEW" />
<category android:name="android.intent.category.DEFAULT" />
<category android:name="android.intent.category.BROWSABLE" />
<data android:scheme="https"
android:host="example.com"
android:path="/oauth2redirect" />
</intent-filter>
</activity>
</application>
</manifest>
After I process the request and user log in, redirect url is applied in custom tab and the screen remains without redirect back to the native app.
Could you please give me some clues to make redirect back to the native app work?
Thanks in advance.
Update
GitHub repository: https://github.com/OldrichTodt/AppAuthExample/blob/master/README.md
Sign in code is called from Xamarin app in MainPage.xaml.cs Here is full code:
public async Task LoginAsync()
{
try
{
var authConfig = await AuthorizationServiceConfiguration.FetchFromIssuerAsync(Uri.Parse("https://example.com"));
AuthState authState = new AuthState(authConfig);
AuthorizationRequest.Builder authReqBuilder = new AuthorizationRequest.Builder(authConfig,
"RealOneGame.Xamarin",
ResponseTypeValues.Code,
Uri.Parse("https://com.example/oauth2redirect"));
authReqBuilder.SetScope("api1 openid profile offline_access");
AuthorizationRequest authReq = authReqBuilder.Build();
AuthorizationService authService = new AuthorizationService(Application.Context);
authService.PerformAuthorizationRequest(authReq, PendingIntent.GetActivity(Application.Context, 0, new Intent(Application.Context, typeof(MyAuthCompleteActivity)), 0),
PendingIntent.GetActivity(Application.Context, 0, new Intent(Application.Context, typeof(MyAuthCanceledActivity)), 0));
}
catch (Exception ex)
{
}
}