Ejemplo n.º 1
0
        public async Task <InvokeResult> ValidateRefreshTokenAsync(string refreshTokenId, string userId)
        {
            var validateFormatResult = ValidateRefreshTokenFormat(refreshTokenId);

            if (!validateFormatResult.Successful)
            {
                return(validateFormatResult);
            }

            var token = await _refreshTokenRepo.GetRefreshTokenAsync(refreshTokenId, userId);

            if (token == null)
            {
                _adminLogger.AddCustomEvent(Core.PlatformSupport.LogLevel.Error, "AuthRequestValidators_ValidateRefreshTokenAsync", UserAdminErrorCodes.AuthRefreshTokenNotInStorage.Message, new KeyValuePair <string, string>("refreshtokenid", refreshTokenId));
                return(InvokeResult.FromErrors(UserAdminErrorCodes.AuthRefreshTokenNotInStorage.ToErrorMessage()));
            }

            if (token.ExpiresUtc.ToDateTime() < DateTime.UtcNow)
            {
                _adminLogger.AddCustomEvent(Core.PlatformSupport.LogLevel.Error, "AuthRequestValidators_ValidateRefreshTokenAsync", UserAdminErrorCodes.AuthRefreshTokenExpired.Message);
                await _refreshTokenRepo.RemoveRefreshTokenAsync(refreshTokenId, userId);

                return(InvokeResult.FromErrors(UserAdminErrorCodes.AuthRefreshTokenExpired.ToErrorMessage()));
            }
            return(InvokeResult.Success);
        }
Ejemplo n.º 2
0
        public async Task <InvokeResult <RefreshToken> > RenewRefreshTokenAsync(RefreshToken oldRefreshToken)
        {
            if (oldRefreshToken == null)
            {
                _adminLogger.AddCustomEvent(Core.PlatformSupport.LogLevel.Error, "RefreshTokenManager_RenewRefreshTokenAsync", UserAdminErrorCodes.AuthMissingRefreshToken.Message);
                return(InvokeResult <RefreshToken> .FromErrors(UserAdminErrorCodes.AuthMissingRefreshToken.ToErrorMessage()));
            }

            var validateRefreshTokenResult = await _authRequestValidators.ValidateRefreshTokenAsync(oldRefreshToken.RowKey, oldRefreshToken.PartitionKey);

            if (!validateRefreshTokenResult.Successful)
            {
                _adminLogger.AddCustomEvent(Core.PlatformSupport.LogLevel.Error, "RefreshTokenManager_RenewRefreshTokenAsync", UserAdminErrorCodes.AuthRefreshTokenExpired.Message,
                                            new KeyValuePair <string, string>("authAppId", oldRefreshToken.AppId),
                                            new KeyValuePair <string, string>("authAppInstanceId", oldRefreshToken.AppInstanceId),
                                            new KeyValuePair <string, string>("authUserId", oldRefreshToken.PartitionKey));

                await _refreshTokenRepo.RemoveRefreshTokenAsync(oldRefreshToken.RowKey, oldRefreshToken.PartitionKey);

                return(InvokeResult <RefreshToken> .FromErrors(UserAdminErrorCodes.AuthRefreshTokenExpired.ToErrorMessage()));
            }

            var newRefreshToken = await GenerateRefreshTokenAsync(oldRefreshToken.AppId, oldRefreshToken.AppInstanceId, oldRefreshToken.PartitionKey);

            if (newRefreshToken.Successful)
            {
                _adminLogger.AddCustomEvent(Core.PlatformSupport.LogLevel.Verbose, "RefreshTokenManager_RenewRefreshTokenAsync", "RefrehTokenRenewed",
                                            new KeyValuePair <string, string>("authAppId", oldRefreshToken.AppId),
                                            new KeyValuePair <string, string>("authAppInstanceId", oldRefreshToken.AppInstanceId),
                                            new KeyValuePair <string, string>("authUserId", oldRefreshToken.PartitionKey));

                await _refreshTokenRepo.RemoveRefreshTokenAsync(oldRefreshToken.RowKey, oldRefreshToken.PartitionKey);
            }

            return(newRefreshToken);
        }