コード例 #1
0
        /// <summary>
        /// Url of the token issuing instance.  E.g. the JWT bearer
        /// authentication middleware will use this URI as base
        /// uri to retrieve the public key that can be used to
        /// validate the token's signature.
        /// </summary>
        /// <param name="config"></param>
        /// <param name="noVersion"></param>
        /// <returns></returns>
        public static string GetAuthorityUrl(this IOAuthConfig config,
                                             bool noVersion = false)
        {
            var authorityUrl = config?.InstanceUrl?.TrimEnd('/');

            var tenantId = config?.TenantId;
            var provider = config.GetProviderName();

            if (string.IsNullOrEmpty(authorityUrl))
            {
                // Default to aad
                authorityUrl = kDefaultAuthorityUrl;
            }
            if (provider == AuthProvider.AzureAD)
            {
                // use v2.0 endpoint of AAD with tenant if set
                if (string.IsNullOrEmpty(tenantId))
                {
                    tenantId = "common";
                }
                authorityUrl += "/" + tenantId;
                if (!noVersion)
                {
                    authorityUrl += "/v2.0";
                }
                return(authorityUrl);
            }

            // Non aad e.g. identity server with optional tenant id.
            if (!string.IsNullOrEmpty(tenantId))
            {
                authorityUrl += "/" + tenantId;
            }
            return(authorityUrl);
        }
コード例 #2
0
        /// <summary>
        /// Returns the provider name
        /// </summary>
        /// <param name="config"></param>
        /// <returns></returns>
        public static string GetProviderName(this IOAuthConfig config)
        {
            var name = config.Provider;

            if (string.IsNullOrEmpty(name))
            {
                return(AuthProvider.Unknown);
            }
            return(name);
        }