我正在使用 IdentityServer4 实现 Xamarin AppAuth 库。在自定义选项卡中授权后,我无法实现重定向回应用程序。授权请求如下图:
AuthorizationRequest.Builder authReqBuilder =
new AuthorizationRequest.Builder(authConfig,
"clientId",
ResponseTypeValues.Code,
Uri.Parse("https://com.example/oauth2redirect"));
authReqBuilder.SetScope("api1 openid profile offline_access");
这是 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>
在我处理请求和用户登录后,重定向 url 应用在自定义选项卡中,屏幕保持不变,没有重定向回本机应用程序。
您能否给我一些线索以使重定向回本机应用程序正常工作?
提前致谢。
更新
GitHub 存储库:https ://github.com/OldrichTodt/AppAuthExample/blob/master/README.md
登录代码是从 MainPage.xaml.cs 中的 Xamarin 应用程序调用的完整代码:
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)
{
}
}