Esempio n. 1
0
        public async Task <IActionResult> OnGetRetrieveChatApiUrlAsync()
        {
            var identityInfo = _configuration.GetSection("IdentityInfo");
            var chatApiUrl   = _configuration.GetSection("ChatpApiUrl").Value;

            var basicTokenRequest = new BasicTokenRequest
            {
                ClientId     = identityInfo.GetSection("ClientId").Value,
                ClientSecret = identityInfo.GetSection("ClientSecret").Value,
                Address      = identityInfo.GetSection("Address").Value,
                Scope        = identityInfo.GetSection("Scope").Value
            };

            var accessToken = await _identityManagerService.GetAccessToken(basicTokenRequest);

            return(new JsonResult($"{chatApiUrl}?token={accessToken}"));
        }
Esempio n. 2
0
        public async Task <string> GetAccessToken(BasicTokenRequest tokenRequest)
        {
            var discoveredDocument = await _httpClient.GetDiscoveryDocumentAsync(tokenRequest.Address);

            var tokeRequest = new TokenRequest();

            var tokenResponse = await _httpClient.RequestClientCredentialsTokenAsync(

                new ClientCredentialsTokenRequest {
                Address      = discoveredDocument.TokenEndpoint,
                ClientId     = tokenRequest.ClientId,
                ClientSecret = tokenRequest.ClientSecret,
                Scope        = tokenRequest.Scope
            }
                );

            return(tokenResponse.AccessToken);
        }