簡體   English   中英

登錄后IdentityServer4不重定向到xamarin.forms android應用

[英]Identityserver4 not redirecting to xamarin.forms android app after login

我已經為解決這個問題工作了幾天,但我不知道是什么問題。 我正在實現Identityserver4,並使用以下客戶端配置啟動並運行它。

public static IEnumerable<Client> GetClients(string somesecret)
            {
                return new List<Client> {
                    new Client {
                            ClientId = "xamarin.app",
                            ClientName = "Xamarin Mobile App.",
                            AllowedGrantTypes = GrantTypes.Code,
                            AccessTokenType = AccessTokenType.Jwt, //default
                            ClientSecrets = new List<Secret> {new Secret(somesecret.Sha256())}, 
                            AllowedScopes = new List<string>
                            {
                                IdentityServerConstants.StandardScopes.OpenId,
                                IdentityServerConstants.StandardScopes.Profile,
                                IdentityServerConstants.StandardScopes.OfflineAccess,
                                //"xamarin.app",
                            },
                            RefreshTokenUsage = TokenUsage.ReUse,
                            AllowAccessTokensViaBrowser = true,
                            AllowOfflineAccess = true,
                            AlwaysIncludeUserClaimsInIdToken = true,
                            RequireConsent = false,
                            RequirePkce = true,
                            RequireClientSecret = false,
                            RedirectUris = new List<string>{ "https://localhost:44310/grants", "https://some-idp-server.net/grants", "com.xamarin.app:/oauth2redirect"}
                    }
                };
            }

我目前使用的所有代碼均基於以下站點的示例;

到目前為止,從我的角度來看,一切看起來都不錯,並且一切正常。 在本地運行Identityserver時,我可以登錄,我的帳戶已正確驗證,並且將我重定向到Identityserver的主頁。

現在,我的xamarin應用程序正在使用以下代碼段連接到IdentityServer。 這也行得通,因為觸發代碼后,我的Identityserver上會顯示登錄屏幕。

var oAuth = new OAuth2AuthenticatorEx("xamarin.app"
                                    , "openid profile"
                                    , new Uri("https://some-idp-server.net/connect/authorize")
                                    //, new Uri("https://some-idp-server.net/grants")
                                    , new Uri("com.xamarin.app:/oauth2redirect")
                                    , isUsingNativeUI:false)
            {
                AccessTokenUrl = new Uri("https://some-idp-server.net/connect/token"),
                ShouldEncounterOnPageLoading = false
            };

            var account = Task.Run(async () => await App.GetCurrentUserAccountAsync("oAuth")).ConfigureAwait(false)
                                                    .GetAwaiter()
                                                    .GetResult();

            if (account != null)
            {
                App.AuthAccount = account;
                App.HttpClient.DefaultRequestHeaders.Add("Authorization", $"Bearer {account.Properties["access_token"]}");

                OAuthLoginPage.LoginSuccess(null);
            }
            else
            {
                oAuth.Completed += Presenter_Completed;
                oAuth.Error += Presenter_Error;

                var presenter = new OAuthLoginPresenter();
                presenter.Completed += Presenter_Completed;
                presenter.Login(oAuth);
            }

但是問題出在登錄后。我沒有看到重定向到應用程序,而是看到空白頁,似乎什么都沒有發生。 這似乎是Identityserver4的某種默認行為,因為在本地運行時,我會看到帶有versionnumber等的默認頁面。但是在部署時,當瀏覽https:// some-idp-時,我還會看到帶有404響應代碼的白頁。直接使用server.net 因此,我懷疑Identityserver假裝不存在安全原因,這是有道理的。

現在,就我對Identityserver的了解而言,我對這個話題還很陌生,實際的問題與redirecturl有關。 研究互聯網也將我推向了這個方向,這實際上使我添加了“ com.xamarin.app:/oauth2redirect”作為身份服務器上客戶端的重定向URL。 但是,仍然沒有運氣。 有人可以幫我嗎?

知道單擊按鈕后正在從頁面渲染器中調用它可能是個好消息。 但是我沒有在這里尋找問題,因為我得到了預期的登錄屏幕。

在Azure上啟用Application Insights之后,我可以看到此問題。 顯然,並非所有遷移都已正確執行。 這引起了問題,因為數據庫中沒有所需的表。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM