コード例 #1
0
        public async Task <CertificateStatus> GetCertificate(string clientAssertion, string certificateHash)
        {
            var accessToken = await _tokenClient
                              .GetAccessToken(_schemeOwnerBaseUrl, _clientId, clientAssertion)
                              .ConfigureAwait(false);

            return(await GetCertificateStatus(accessToken, certificateHash).ConfigureAwait(false));
        }
コード例 #2
0
        public async Task <(IToken Token, ResultState ResultState)> GetAccessToken(string corpId, string secret)
        {
            var cacheKey   = GetTokenCachingKey(corpId, secret);
            var cacheToken = await _cache.GetStringAsync(cacheKey);

            if (cacheToken != null)
            {
                var token = JsonConvert.DeserializeObject <AccessToken>(cacheToken);

                if (IsExpired(token))
                {
                    return(token, ResultState.OkFromCache);
                }
            }

            var resp = await _tokenClient.GetAccessToken(corpId, secret);

            var result = await resp.ReadAsResult <AccessToken>();

            if (result.State.Successed)
            {
                await _cache.SetStringAsync(cacheKey, JsonConvert.SerializeObject(result.Payload));
            }

            return(result);
        }
コード例 #3
0
        public async Task <(AccessToken AccessToken, ResultState ResultState)> GetAccessToken(string appId, string appSecret)
        {
            var cacheToken = await _cache.GetStringAsync(appId);

            if (cacheToken != null)
            {
                var token = JsonConvert.DeserializeObject <AccessToken>(cacheToken);

                if (token.CreateUtcTime + token.ExpiresIn > DateTime.UtcNow - TimeSpan.FromMinutes(-5))
                {
                    return(token, ResultState.OkFromCache);
                }
            }

            var resp = await _tokenClient.GetAccessToken(appId, appSecret);

            var result = await resp.ReadAsResult <AccessToken>();

            if (result.State.Successed)
            {
                await _cache.SetStringAsync(appId, JsonConvert.SerializeObject(result.Payload));
            }

            return(result);
        }
コード例 #4
0
        private async Task <string> GetAccessToken(ClientAssertion clientAssertion)
        {
            var assertion = new TokenClient.Models.ClientAssertion
            {
                Subject    = _partyDetailsOptions.ClientId,
                Issuer     = _partyDetailsOptions.ClientId,
                Audience   = _schemeOwnerClientOptions.ClientId,
                JwtId      = clientAssertion.JwtId,
                IssuedAt   = clientAssertion.IssuedAt,
                Expiration = clientAssertion.Expiration
            };

            return(await _tokenClient.GetAccessToken(
                       _schemeOwnerClientOptions.BaseUri,
                       _partyDetailsOptions.ClientId,
                       assertion));
        }
コード例 #5
0
        private async Task <string> GetAccessToken(ClientAssertion clientAssertion)
        {
            var assertion = new TokenClient.Models.ClientAssertion
            {
                Subject    = _partyDetailsOptions.ClientId,
                Issuer     = _partyDetailsOptions.ClientId,
                Audience   = _authorizationRegistryClientOptions.ClientId,
                JwtId      = clientAssertion.JwtId,
                IssuedAt   = clientAssertion.IssuedAt,
                Expiration = clientAssertion.Expiration
            };

            var accessToken = await _tokenClient
                              .GetAccessToken(_authorizationRegistryClientOptions.BaseUri,
                                              _partyDetailsOptions.ClientId,
                                              assertion);

            return(accessToken);
        }
        private async Task <string> GetAccessToken(ClientAssertion clientAssertion)
        {
            var authorityAudience = $"{_authorizationRegistryBaseUrl}connect/token";

            var assertion = new TokenClient.ClientAssertion
            {
                Subject           = _clientId,
                Issuer            = _clientId,
                Audience          = _clientId,
                AuthorityAudience = authorityAudience,
                JwtId             = clientAssertion.JwtId,
                IssuedAt          = clientAssertion.IssuedAt,
                Expiration        = clientAssertion.Expiration
            };

            var accessToken = await _tokenClient
                              .GetAccessToken(_authorizationRegistryBaseUrl, _clientId, assertion, _privateKey, _publicKeys)
                              .ConfigureAwait(false);

            return(accessToken);
        }