我正在尝试使用Xamarin.Forms在Dropbox中进行身份验证,我使用以下代码。
this.oauth2State = Guid.NewGuid().ToString("N");
var authorizeUri = DropboxOAuth2Helper.GetAuthorizeUri(OAuthResponseType.Token, AppKeyDropboxtoken, new Uri(RedirectUri), this.oauth2State, false, false, null, loginAgain);
webView = new CustomWebview
{
Source = authorizeUri.AbsoluteUri
};
webView.Navigating += this.WebViewOnNavigating;
//Grid Layout
Grid lyStack = new Grid
{
Children =
{
webView,
lyTitle,
},
HorizontalOptions = LayoutOptions.FillAndExpand,
VerticalOptions = LayoutOptions.FillAndExpand,
Padding = new Thickness(0, 20, 0, 0),
};
this.Content = lyStack;
但是当我将App提交到生产环境时,会收到以下错误消息:
你好,
您的生产关键请求被拒绝的原因如下:
您的应用当前正在内部处理OAuth应用授权流程 Web视图,而不是系统浏览器。 OAuth应用授权 流程应在用户的系统浏览器中处理。看到这里 更多信息: https://www.dropbox.com/developers/documentation/http/documentation#oauth2-authorize
如果您认为不应该拒绝您的应用,或者重新提交 您的请求,请通过api-program@dropbox.com向我们发送电子邮件。
答案 0 :(得分:0)
使用Xamarin.Auth解决了该问题,即它的工作方式:
private string oauth2State;
private const string RedirectUri = "https://www.myredirecturl.com/en/";
private string AccessToken { get; set; }
private const string AppKeyDropboxtoken = "xxxxxxxxxxxxxxx";
private void openDropbox()
{
this.oauth2State = Guid.NewGuid().ToString("N");
var authorizeUri = DropboxOAuth2Helper.GetAuthorizeUri(OAuthResponseType.Token, AppKeyDropboxtoken, new Uri(RedirectUri), this.oauth2State, false, false, null, false);
//Authorize URI
OAuth2Authenticator auth = new OAuth2Authenticator
(
clientId: AppKeyDropboxtoken,
scope: "",
authorizeUrl: new Uri(authorizeUri.AbsoluteUri),
redirectUrl: new Uri(RedirectUri),
isUsingNativeUI: false
);
auth.Completed += (sender, eventArgs) =>
{
if (eventArgs.IsAuthenticated)
{
Debug.Write("IsAuthenticated . . . . . ");
// Use eventArgs.Account to do wonderful things
this.AccessToken = eventArgs.Account.Properties["access_token"].ToString();
Debug.WriteLine("AccessToken: " + this.AccessToken);
//Do Something
}
};
var presenter = new Xamarin.Auth.Presenters.OAuthLoginPresenter();
presenter.Login(auth);
}
并在演示者平台上进行初始化,
您的OnCreate方法上的Android
global::Xamarin.Auth.Presenters.XamarinAndroid.AuthenticationConfiguration.Init(this, bundle);
AppDelegate.cs上的iOs
global::Xamarin.Auth.Presenters.XamarinIOS.AuthenticationConfiguration.Init();