private async Task <string> CustomProviderAuthentication(RefreshTokenInfo refreshTokenInfo) { try { var ret = await _mobileServiceClient.InvokeApiAsync <CustomLoginResult>( _customLoginControllerName, HttpMethod.Get, new Dictionary <string, string> { { "userId", refreshTokenInfo.UserId }, { "refreshToken", refreshTokenInfo.RefreshToken } }); if (ret != null) { _mobileServiceClient.CurrentUser = new MobileServiceUser(ret.UserId) { MobileServiceAuthenticationToken = ret.MobileServiceAuthenticationToken }; refreshTokenInfo.RefreshToken = ret.RefreshToken; _accountStoreService.StoreTokenInSecureStore(refreshTokenInfo); return(_mobileServiceClient.CurrentUser.MobileServiceAuthenticationToken); } else { return(string.Empty); } } catch (MobileServiceInvalidOperationException) { return(string.Empty); } }
/// <summary> /// Logins user using custom login controller and stores token in account store. /// Stored token will be used in <see cref="Authenticate"/> method. /// Sets logged user to <see cref="AuthMobileServiceClient.CurrentUser"/> and /// access to authorized requests should be gratned. /// </summary> /// <param name="email">The email.</param> /// <param name="password">The password.</param> /// <returns>Login result.</returns> public async Task <bool> Login(string email, string password) { var loginRequest = new CustomLoginRequest() { UserId = email, Password = password }; var ret = await _mobileServiceClient.InvokeApiAsync <CustomLoginRequest, CustomLoginResult>( _customLoginControllerName, loginRequest); if (ret != null) { _mobileServiceClient.CurrentUser = new MobileServiceUser(ret.UserId) { MobileServiceAuthenticationToken = ret.MobileServiceAuthenticationToken }; _accountStoreService.StoreTokenInSecureStore(new RefreshTokenInfo() { UserId = ret.UserId, Provider = "custom", RefreshToken = ret.RefreshToken, }); return(true); } else { return(false); } }
/// <summary> /// Logins user using provider and stores token in acount store. /// Stored token will be used in <see cref="Authenticate"/> method. /// Sets logged user to <see cref="AuthMobileServiceClient.CurrentUser"/> and /// access to authorized requests should be gratned. /// </summary> /// <param name="provider">The provider.</param> /// <returns>Login result.</returns> public async Task <bool> Login(MobileServiceAuthenticationProvider provider) { var parameters = new Dictionary <string, string> { { "access_type", "offline" }, { "prompt", "consent" } }; await _mobileServiceClient.LoginAsync(_context, provider, _uriScheme, parameters); if (_mobileServiceClient.CurrentUser != null) { _accountStoreService.StoreTokenInSecureStore(new RefreshTokenInfo() { UserId = _mobileServiceClient.CurrentUser.UserId, Provider = provider.ToString(), RefreshToken = _mobileServiceClient.CurrentUser.MobileServiceAuthenticationToken }); return(true); } else { return(false); } }