首页 > 解决方案 > 如何使用 ASP.NET Core 3.1 将 Android 应用程序集成到 Identity Server 以进行身份​​验证?

问题描述

我已经使用 Angular 模板创建了 ASP.NET Core 项目,并使用 Visual Studio 进行了身份验证。现在我正在开发 Android 应用程序,并希望将其与我现有的 ASP.NET CORE 3.1 WEB API(后端)集成。我在 appsettings.json 中为我的 android 应用添加了客户端,如下所示:

"IdentityServer": {
    "Clients": {
       "MyAngularApp": {
           "Profile": "IdentityServerSPA"
       },
       "MyMobileApp": {
           "Profile": "NativeApp"
       }
    }
}

当我调用我的配置端点“https://localhost:4042/_configuration/MyMobileApp”时,我得到了以下响应;

{"authority":"https://localhost:4042","client_id":"MyMobileApp","redirect_uri":"urn:ietf:wg:oauth:2.0:oob","post_logout_redirect_uri":"urn:ietf:wg:oauth:2.0:oob","response_type":"code","scope":"offline_access MyAppAPI openid profile"}

我有以下问题;

我在 Android 中使用 AppAuth 库与 Identity Server 集成。

标签: androidasp.net-coreauthenticationidentityserver4access-token

解决方案


在 appsetting.json 中尝试您必须使用 IdentityServer - 客户端尝试这可能是您的问题将得到解决

"IdentityServer": {
  "IssuerUri": "urn:sso.company.com",
  "Clients": [
    {
      "Enabled": true,
      "ClientId": "local-dev",
      "ClientName": "Local Development",
      "ClientSecrets": [ { "Value": "<Insert Sha256 hash of the secret encoded as Base64 string>" } ],
      "AllowedGrantTypes": [ "implicit" ],
      "AllowedScopes": [ "openid", "profile" ],
      "RedirectUris": [ "https://localhost:5001/signin-oidc" ],
      "RequireConsent": false
    }
  ]
}


推荐阅读