【问题标题】:How sensitive is the Google OpenID Discovery Document to change?Google OpenID 发现文档的更改有多敏感?
【发布时间】:2020-08-04 13:06:21
【问题描述】:

我想做什么

我正在尝试实施 Google OpenID Connect 作为使用 Google 说明登录 ASP.NET Core 3.1 网站的一种方式:

https://developers.google.com/identity/protocols/oauth2/openid-connect#server-flow

在服务器流的step 2(向 Google 发送身份验证请求)下,他们建议从 their OpenID 发现文档中检索信息:

您应该使用 authorization_endpoint 元数据值从 Discovery document 检索基本 URI。

我目前正在尝试通过using Newtonsoft.JsonJSON 动态反序列化为Dictionary<string, string>。但这给了我一些问题(似乎无法反序列化 JSON string array),我正在考虑改变我的策略,为发现文档创建一个 model 并创建一个 using System.Text.Json 以反序列化。

现在我的问题是

Google 的发现文档对导致我必须更新 DiscoveryDocument.cs model 的更改有多敏感?

困境

使用Newtonsoft.Json 方式,一切仍然有效,即使 Google 决定删除随机密钥。

但现在使用System.Text.Json 对我来说是一种简单的方法,并且消除了对 Newtonsoft 库的依赖,但如果 Google 的 Discovery Document 发生更改,我以后可能会遇到麻烦。

【问题讨论】:

    标签: json.net openid-connect asp.net-core-3.1 google-openidconnect


    【解决方案1】:

    我认为您会更轻松地使用 Microsoft.IdentityModel.Protocols 和 Microsoft.IdentityModel.Protocols.OpenIdConnect NuGet 包并使用包含的解析器为您完成所有工作。文档中的项目非常标准化,但并非每个提供商都提供所有项目。

    public class OpenIDSettings : IOpenIDSettings
    {
        public string Issuer { get; }
        public string jwks_uri { get; }
        public string authorization_endpoint { get; }
        public string token_endpoint { get; }
        public string userinfo_endpoint { get; }
        public string end_session_endpoint { get; }
        public string check_session_iframe { get; }
        public string revocation_endpoint { get; }
        public string introspection_endpoint { get; }
        public string device_authorization_endpoint { get; }
    
        public ICollection<string> scopes_supported { get; }
        public ICollection<string> claims_supported { get; }
    
        public OpenIDSettings(string endpoint)
        {
            var configurationManager = new ConfigurationManager<OpenIdConnectConfiguration>(
                $"{endpoint}/.well-known/openid-configuration",
                new OpenIdConnectConfigurationRetriever());
    
            //If you get an exception here, then provider is not running or reachable
            var document = configurationManager.GetConfigurationAsync().Result;
    
            //Add the necessary code to populate the properties in this class
            Issuer = document.Issuer;
            jwks_uri = document.JwksUri;
            authorization_endpoint = document.AuthorizationEndpoint;
            token_endpoint = document.TokenEndpoint;
            userinfo_endpoint = document.UserInfoEndpoint;
            end_session_endpoint = document.EndSessionEndpoint;
            check_session_iframe = document.CheckSessionIframe;
    
            scopes_supported = document.ScopesSupported;
            claims_supported = document.ClaimsSupported;
    
            if (document.AdditionalData.ContainsKey("revocation_endpoint"))
                revocation_endpoint = (string)(document.AdditionalData["revocation_endpoint"]);
            
            if (document.AdditionalData.ContainsKey("introspection_endpoint"))
                introspection_endpoint = (string)(document.AdditionalData["introspection_endpoint"]);
    
            if (document.AdditionalData.ContainsKey("device_authorization_endpoint"))
                device_authorization_endpoint = (string)(document.AdditionalData["device_authorization_endpoint"]);
        }
    }
    

    【讨论】:

    • 如果我理解正确,您是否建议我为 Azure Active Directory 使用 NuGet 包并使用包含的解析器?如果我不使用 Azure Active Directory,我不想依赖它。有没有更通用的 OpenID Connect 包可以推荐?
    • 作为替代方案,您可以尝试 github.com/IdentityModel/IdentityModel,这是一个客户端帮助程序库来进行验证。github.com/IdentityModel/IdentityModel 的源代码希望得到一个可以接受的答案。
    猜你喜欢
    • 2011-03-13
    • 2010-12-26
    • 2019-01-12
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2021-12-12
    • 1970-01-01
    • 2014-01-12
    相关资源
    最近更新 更多