Beispiel #1
0
        public static async Task <JwtAuthToken> RequestJwtTokenAsync(this HttpClient httpClient, Uri requestUri,
                                                                     JwtTokenRequest tokenRequest, string tokenPropertyName)
        {
            using var response =
                      await httpClient.PostAsJsonAsync(requestUri, tokenRequest).ConfigureAwait(false);

            response.EnsureSuccessStatusCode();

            var responseContent = await response.Content.ReadAsStringAsync()
                                  .ConfigureAwait(false);

            var jsonObject    = JObject.Parse(responseContent);
            var tokenProperty = jsonObject
                                .Properties()
                                .FirstOrDefault(p =>
                                                string.IsNullOrEmpty(tokenPropertyName) || p.Name.Equals(tokenPropertyName,
                                                                                                         StringComparison.InvariantCultureIgnoreCase));

            if (tokenProperty == null)
            {
                throw new JwtTokenNotFoundException(tokenPropertyName, responseContent);
            }

            var authToken = tokenProperty.Value.ToString();

            return(new JwtAuthToken(authToken));
        }
Beispiel #2
0
        public async Task <JwtTokenInfo> RequestTokenInfoAsync(Uri requestUri, JwtTokenRequest tokenRequest)
        {
            var authToken = await _httpClient.RequestJwtTokenAsync(requestUri, tokenRequest);

            return(new JwtTokenInfo(authToken.Token));
        }
Beispiel #3
0
        public async Task <string> RequestTokenAsync(Uri requestUri, JwtTokenRequest tokenRequest)
        {
            var tokenInfo = await RequestTokenInfoAsync(requestUri, tokenRequest);

            return(tokenInfo.Token);
        }
Beispiel #4
0
 public static Task <JwtAuthToken> RequestJwtTokenAsync(this HttpClient httpClient, Uri requestUri,
                                                        JwtTokenRequest tokenRequest)
 {
     return(httpClient.RequestJwtTokenAsync(requestUri, tokenRequest, string.Empty));
 }