Dropbox无法使用Xamarin.Forms进行身份验证

问题描述 投票:0回答:1

我正在尝试使用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;

但是当我将应用程序提交到生产环境时,出现以下错误消息:

你好,

您的生产关键请求由于以下原因而被拒绝:

您的应用当前正在处理内部的OAuth应用授权流程Web视图,而不是系统浏览器。 OAuth应用授权流应在用户的系统浏览器中处理。看到这里更多信息:https://www.dropbox.com/developers/documentation/http/documentation#oauth2-authorize

[如果您认为不应拒绝您的应用,或重新提交您的请求,请给我们发送电子邮件至[email protected]

xamarin xamarin.forms dropbox
1个回答
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上的iO

global::Xamarin.Auth.Presenters.XamarinIOS.AuthenticationConfiguration.Init();
© www.soinside.com 2019 - 2024. All rights reserved.