我设法在xamarin android上显示登录和同意屏幕。在允许浏览器上的同意之后,浏览器不会自动重定向回应用程序。
这些是我的设置:
namespace OAuthNativeFlow.Droid
{
[Activity(Label = "OAuthNativeFlow.Droid", Icon = "@drawable/icon", Theme = "@style/MyTheme", MainLauncher = true, ConfigurationChanges = ConfigChanges.ScreenSize | ConfigChanges.Orientation)]
[IntentFilter(new[] { Intent.ActionView },
Categories = new[]
{
Intent.ActionView,
Intent.CategoryDefault,
Intent.CategoryBrowsable
},
DataScheme = "myTest",
DataPathPrefix = "/",
AutoVerify = true)
]
public class MainActivity : global::Xamarin.Forms.Platform.Android.FormsAppCompatActivity
{
这是用户单击登录按钮时的代码。
switch (Device.RuntimePlatform)
{
case Device.iOS:
clientId = Constants.iOSClientId;
redirectUri = Constants.iOSRedirectUrl;
break;
case Device.Android:
clientId = Constants.AndroidClientId;
redirectUri = Constants.AndroidRedirectUrl;
break;
}
account = store.FindAccountsForService(Constants.AppName).FirstOrDefault();
var authenticator = new OAuth2Authenticator(
clientId,
"Staff Mobile App Client",
Constants.Scope,
new Uri(Constants.AuthorizeUrl),
new Uri(redirectUri),
new Uri(Constants.AccessTokenUrl),
null,
true);
authenticator.Completed += OnAuthCompleted;
authenticator.Error += OnAuthError;
AuthenticationState.Authenticator = authenticator;
var presenter = new Xamarin.Auth.Presenters.OAuthLoginPresenter();
presenter.Login(authenticator);
这些代码来自Xamarin示例:https://developer.xamarin.com/samples/xamarin-forms/WebServices/OAuthNativeFlow/
我是否需要在身份服务器中添加任何内容。我不是通过Google登录,而是自己的身份服务器。