Пример #1
0
        public OpenIdConnectCachingSecurityTokenProvider(string metadataEndpoint)
        {
            _metadataEndpoint = metadataEndpoint;
            _configManager    = new ConfigurationManager <OpenIdConnectConfiguration>(metadataEndpoint, new OpenIdConnectConfigurationRetriever());

            RetrieveMetadata();
        }
Пример #2
0
        public static async Task <ClaimsPrincipal> Validate(string accessToken)
        {
            string stsDiscoveryEndpoint = "https://login.microsoftonline.com/AZURE_TENANT_ID/.well-known/openid-configuration";

            ConfigurationManager <OpenIdConnectConfiguration> configManager = new Microsoft.IdentityModel.Protocols.ConfigurationManager <OpenIdConnectConfiguration>(stsDiscoveryEndpoint);

            OpenIdConnectConfiguration config = await configManager.GetConfigurationAsync();

            System.IdentityModel.Tokens.TokenValidationParameters validationParameters = new System.IdentityModel.Tokens.TokenValidationParameters
            {
                ValidIssuer          = config.Issuer,
                ValidateAudience     = false,
                IssuerSigningTokens  = config.SigningTokens,
                CertificateValidator = X509CertificateValidator.None
            };

            JwtSecurityTokenHandler tokendHandler = new JwtSecurityTokenHandler();

            System.IdentityModel.Tokens.SecurityToken jwt = new JwtSecurityToken();

            ClaimsPrincipal result = tokendHandler.ValidateToken(accessToken, validationParameters, out jwt);

            return(result);
        }