Ejemplo n.º 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
                });
            }
        }
Ejemplo n.º 2
0
        private string EncryptPayload(AppCredentialsModel decryptedAppCredentials)
        {
            var jsonSerializedObject = JsonConvert.SerializeObject(decryptedAppCredentials);
            var encryptedPayload     = _encryptionService.Encrypt(jsonSerializedObject);

            return(Convert.ToBase64String(encryptedPayload));
        }
Ejemplo n.º 3
0
        public async Task <AppAuthTokenModel> GetSession(string sessionId)
        {
            sessionId = sessionId.Replace("\"", "");
            try
            {
                var appCredentials = new AppCredentialsModel
                {
                    Name   = _authConfig.AppName,
                    Secret = _authConfig.AppSecret
                };
                var encryptedAppCredentials = EncryptPayload(appCredentials);

                // get initial session.
                var responseResult = await _client.GetSession(encryptedAppCredentials, sessionId);

                if (responseResult.ResponseStatusCode != (int)HttpStatusCode.OK)
                {
                    return(responseResult);
                }

                // Get dashboard token.
                var newTokenModel = await ValidateAndIssueToken(responseResult.Token);

                if (newTokenModel.ResponseStatusCode != (int)HttpStatusCode.OK)
                {
                    return(newTokenModel);
                }
                responseResult.Token = newTokenModel.Token;

                await ConvertLegacyData(responseResult);

                return(responseResult);
            }
            catch (Exception ex)
            {
                _logger.LogError(ex, "Error on AppAuthApiService->GetSession");
                return(new AppAuthTokenModel
                {
                    ResponseStatusCode = 500,
                    ResponseMessage = "Internal Server Error",
                });
            }
        }