Exemple #1
0
        public async Task <AppAuthTokenModel> ValidateAndIssueToken(string inboundToken)
        {
            var statusCode     = 0;
            var responseResult = new AppAuthTokenModel();

            try
            {
                var appCredentials = new AppCredentialsModel
                {
                    Name   = _authConfig.AppName,
                    Secret = _authConfig.AppSecret
                };

                var encryptedAppCredentials = EncryptPayload(appCredentials);
                var response = await _client.ValidateAndIssueToken(encryptedAppCredentials, inboundToken);

                return(response);
            }
            catch (Exception ex)
            {
                _logger.LogError(ex, "Error on AppAuthApiService->ValidateToken");
                // this can occur if the jwt token has expired
                return(new AppAuthTokenModel
                {
                    ResponseStatusCode = statusCode,
                    ResponseMessage = responseResult.ResponseMessage
                });
            }
        }
        public async Task <AppAuthTokenModel> ValidateAndIssueToken(string encryptedAppCredentials, string inboundToken)
        {
            var request = new HttpRequestMessage(HttpMethod.Get, ValidateTokenApiRoute);

            request.Headers.Accept.Add(new MediaTypeWithQualityHeaderValue("application/json"));
            request.Headers.Add("encryptedCredentials", encryptedAppCredentials);
            request.Headers.Authorization = new AuthenticationHeaderValue("Bearer", inboundToken);

            using (var response = await _client.SendAsync(request))
            {
                var statusCode = (int)response.StatusCode;
                if (!response.IsSuccessStatusCode)
                {
                    var ex = new HttpRequestException(string.Format("{0} ({1})", (int)response.StatusCode, response.ReasonPhrase));
                    _logger.LogError(ex, "Error on AppAuthApiService->ValidateToken");

                    return(new AppAuthTokenModel
                    {
                        ResponseStatusCode = statusCode,
                        ResponseMessage = response.ReasonPhrase
                    });
                }

                var result = await response.Content.ReadAsStringAsync();

                var responseResult = new AppAuthTokenModel()
                {
                    Token = JsonConvert.DeserializeObject <string>(result),
                    ResponseStatusCode = statusCode
                };

                if (string.IsNullOrEmpty(responseResult.Token))
                {
                    return(new AppAuthTokenModel
                    {
                        ResponseStatusCode = 401,
                        ResponseMessage = "Unauthorized",
                    });
                }

                return(responseResult);
            }
        }
Exemple #3
0
 private async Task ConvertLegacyData(AppAuthTokenModel responseResult)
 {
     return; // TODO: Many apps may have data that has an id that is different from what might have been passed in by the host.
             // This is where you would convert that data to something that this app can use.
 }