【发布时间】:2019-07-03 14:13:33
【问题描述】:
我正在尝试让 Xamarin 应用程序与身份服务器一起使用。我已按照以下步骤操作:
1) 下载:https://github.com/IdentityModel/IdentityModel.OidcClient.Samples/tree/master/XamarinForms 2) 从第 1 点运行 Xamarin Forms 应用程序。它按预期工作,即我可以以 Bob 身份登录,并且我通过了面向公众的演示应用程序的身份验证:https://demo.identityserver.io
它按预期工作到这里。
3) 然后我在这里下载面向公众的演示应用程序:https://github.com/IdentityServer/IdentityServer4.Demo。将其添加到 Xamarin 解决方案中。 4)在溶液中;进行查找和替换 - 从 https://demo.identityserver.io 到 http://localhost:24997/(这是我的身份服务器在解决方案中的 URL)。
5) 注释掉以下代码行,因为我没有使用 Azure:
//Startup.cs
//.AddGoogle("Google", options =>
//{
// options.SignInScheme = IdentityServerConstants.ExternalCookieAuthenticationScheme;
// options.ClientId = Configuration["Secret:GoogleClientId"];
// options.ClientSecret = Configuration["Secret:GoogleClientSecret"];
//})
//.AddOpenIdConnect("aad", "Sign-in with Azure AD", options =>
//{
// options.Authority = "https://login.microsoftonline.com/common";
// options.ClientId = "https://leastprivilegelabs.onmicrosoft.com/38196330-e766-4051-ad10-14596c7e97d3";
// options.SignInScheme = IdentityServerConstants.ExternalCookieAuthenticationScheme;
// options.SignOutScheme = IdentityServerConstants.SignoutScheme;
// options.ResponseType = "id_token";
// options.CallbackPath = "/signin-aad";
// options.SignedOutCallbackPath = "/signout-callback-aad";
// options.RemoteSignOutPath = "/signout-aad";
// options.TokenValidationParameters = new TokenValidationParameters
// {
// ValidateIssuer = false,
// ValidAudience = "165b99fd-195f-4d93-a111-3e679246e6a9",
// NameClaimType = "name",
// RoleClaimType = "role"
// };
//})
//Program.cs
//.ConfigureAppConfiguration((ctx, builder) =>
//{
// var config = builder.Build();
// var tokenProvider = new AzureServiceTokenProvider();
// var kvClient = new KeyVaultClient((authority, resource, scope) => tokenProvider.KeyVaultTokenCallback(authority, resource, scope));
// builder.AddAzureKeyVault(config["KeyVault:BaseUrl"], kvClient, new DefaultKeyVaultSecretManager());
//})
6) 添加选项。RequireHttpsMetadata = false;到 IdentityServer.Startup。
然后我运行 Xamarin 应用程序和身份服务器。我在 Xamarin 应用程序内的以下行中看到错误(第一行:MainPage.Login_Clicked):
_result = await _client.LoginAsync(new LoginRequest());
错误是:Error connecting to http://localhost:24997/.well-known/openid-configuration
有什么明显的我做错了吗?
【问题讨论】:
-
1) 消息中还有更多内容吗?该代码表明可能存在相关的原因短语。 2) 如果您自己在浏览器中打开失败的 URL,会发生什么?
-
1) 内部异常说套接字异常 2) 我可以看到网页。会不会是 xamarin 设备看不到 localhost(身份服务器)。也许我需要浏览到 IP 地址/域名而不是 localhost?
-
是的,这听起来很可能是原因。我相信你知道,localhost 在两个不同的设备上意味着不同的东西。
-
试过了,没有任何区别。再次按照我的指示,得到了相同的结果。您是否尝试按照我的指示进行操作。你得到了什么结果?再次感谢。
-
我无法按照您的说明进行操作,因为我现在没有 Xamarin 设置。等我有时间玩的时候看看能不能试试。
标签: c# xamarin xamarin.forms xamarin.android identityserver4