예제 #1
0
        internal async Task <string> GetTokenEndpointAsync(GraphQLDataAdapterMetadata adapterMetadata)
        {
            var discoveryResponse = await DiscoveryClient.GetAsync(adapterMetadata.Credentials.Issuer);

            if (discoveryResponse.IsError)
            {
                throw new Exception("Auth discovery failure.");
            }

            return(discoveryResponse.TokenEndpoint);
        }
예제 #2
0
        internal async Task <string> GetAuthenticationTokenAsync(GraphQLDataAdapterMetadata adapterMetadata)
        {
            var tokenEndpoint = await GetTokenEndpointAsync(adapterMetadata);

            var client        = adapterMetadata.Credentials.ClientId;
            var secret        = adapterMetadata.Credentials.ClientSecret;
            var scope         = adapterMetadata.Credentials.Scopes;
            var tokenClient   = new TokenClient(tokenEndpoint, client, secret);
            var tokenResponse = await tokenClient.RequestClientCredentialsAsync(scope);

            if (tokenResponse.IsError)
            {
                // TODO: Log this... and throw exception...
                return(null);
            }

            return(tokenResponse.AccessToken);
        }