public async Task <ApiResponse <T> > RegisterUserAsync <T>(RegistrationRequestModel requestModel) where T : IAccessModel
        {
            var result = await _requestSenderService
                         .SendAsync <ApiResponse <T> >(HttpMethod.Post, "https://dev-auth.op.today/v1/identity/registration", requestModel);

            if (result.Success)
            {
                await SetAuthDataAsync(result.Data, requestModel.DeviceId);
            }

            return(result);
        }
Example #2
0
        private async Task <string> RefreshTokenAsync <T>() where T : IAccessModel
        {
            var refreshToken = await _localStorage.GetItemAsync <string>(LocalStorageKey.RefreshToken.ToString());

            if (string.IsNullOrWhiteSpace(refreshToken))
            {
                throw new ApplicationException("Something went wrong during the refresh token action");
            }
            var deviceId = await _localStorage.GetItemAsync <string>(LocalStorageKey.DeviceId.ToString());

            if (string.IsNullOrWhiteSpace(deviceId))
            {
                throw new ApplicationException("Something went wrong during the refresh token action");
            }

            var requestModel = new RefreshTokenRequestModel()
            {
                Token      = refreshToken,
                ClientType = ClientType.Web,
                DeviceId   = deviceId
            };

            var result = await _requestSenderService
                         .SendAsync <ApiResponse <T> >(HttpMethod.Post, "https://dev-auth.op.today/v1/identity/login/refresh", requestModel);

            if (!result.Success)
            {
                throw new ApplicationException("Something went wrong during the refresh token action");
            }

            var authToken = result.Data.GetAuthToken();

            await _localStorage.SetItemAsync(LocalStorageKey.AuthToken.ToString(), authToken);

            await _localStorage.SetItemAsync(LocalStorageKey.RefreshToken.ToString(), result.Data.GetRefreshToken());

            _requestSenderService.Client.DefaultRequestHeaders.Authorization = new AuthenticationHeaderValue("bearer", authToken);
            _authStateProvider.NotifyUserAuthentication(result.Data.GetAuthToken());

            return(authToken);
        }