public static async Task DoLoginAsync(Settings.AuthOption authOption) { if (authOption == Settings.AuthOption.GuestAccess) { Settings.Current.CurrentUserId = Settings.Current.DefaultUserId; return; // can't authenticate } var mobileClient = DependencyService.Get <IPlatform>(); var user = authOption == Settings.AuthOption.Facebook ? await mobileClient.LoginFacebookAsync() : await mobileClient.LoginAsync(MobileServiceAuthenticationProvider.WindowsAzureActiveDirectory); App.Instance.AuthenticatedUser = user; System.Diagnostics.Debug.WriteLine("Authenticated with user: "******"ManageUser", System.Net.Http.HttpMethod.Get, null); Debug.WriteLine($"Set current userID to: {Settings.Current.CurrentUserId}"); AuthStore.CacheAuthToken(user); }
private void button1_Click(object sender, EventArgs e) { var uri = new Uri("https://login.microsoftonline.com/common/oauth2/v2.0/authorize?client_id=" + client_id.Text + "&scope=files.readwrite+offline_access&response_type=code&redirect_uri=" + redirect_uri.Text); webBrowser1.Navigated += new WebBrowserNavigatedEventHandler((obj, ergs) => { System.Diagnostics.Debug.WriteLine(webBrowser1.Url.ToString()); if (webBrowser1.Url.ToString().StartsWith(redirect_uri.Text)) { if (AuthStore.TryAuthentication( client_id.Text, client_secret.Text, redirect_uri.Text, webBrowser1.Url.ToString().Split('=')[1])) { this.Close(); } } }); webBrowser1.Url = uri; }
protected override async Task <HttpResponseMessage> SendAsync(HttpRequestMessage request, CancellationToken cancellationToken) { if (this.Client == null) { throw new InvalidOperationException("Make sure to set the 'Client' property in this handler before using it."); } // Cloning the request, in case we need to send it again var clonedRequest = await CloneRequestAsync(request); var response = await base.SendAsync(clonedRequest, cancellationToken); if (response.StatusCode == HttpStatusCode.Unauthorized) { try { AuthStore.DeleteTokenCache(); // cached token was invalid, so should clear it await DoLoginAsync(Settings.Current.AuthenticationType); clonedRequest = await CloneRequestAsync(request); clonedRequest.Headers.Remove("X-ZUMO-AUTH"); clonedRequest.Headers.Add("X-ZUMO-AUTH", Client.CurrentUser.MobileServiceAuthenticationToken); // Resend the request response = await base.SendAsync(clonedRequest, cancellationToken); } catch (InvalidOperationException) { // user cancelled auth, so return the original response return(response); } } return(response); }
protected override async Task OnInitAsync() { if (!await AuthStore.GetAccessToken()) { UriHelper.NavigateTo("/login"); return; } }
public async Task LogoutAsync() { LoginManager.Instance.LogOut(); CookieManager.Instance.RemoveAllCookie(); AuthStore.DeleteTokenCache(); await App.Instance.MobileService.LogoutAsync(); }
public async Task LogoutAsync() { foreach (var cookie in NSHttpCookieStorage.SharedStorage.Cookies) { NSHttpCookieStorage.SharedStorage.DeleteCookie(cookie); } AuthStore.DeleteTokenCache(); await App.Instance.MobileService.LogoutAsync(); }
private MobileServiceUser GetCachedUser() { var user = AuthStore.GetUserFromCache(); if (user != null) { App.Instance.MobileService.CurrentUser = user; } return(user); }
private async Task <PodioOAuth> Authenticate(Dictionary <string, string> attributes) { attributes["client_id"] = ClientId; attributes["client_secret"] = ClientSecret; PodioOAuth podioOAuth = await Post <PodioOAuth>("/oauth/token", attributes, true).ConfigureAwait(false); this.OAuth = podioOAuth; AuthStore.Set(podioOAuth); return(podioOAuth); }
protected async Task SubmitFrom() { var vm = new TokenViewModel { Email = Email, Password = Password }; var response = await Http.PostJsonAsync <TokenResponse>("api/Token/Login", vm); await AuthStore.Login(response.Token); await Hub.Connect(); UriHelper.NavigateTo("/"); }
public ResourceGuruClient(string clientId, string clientSecret, IAuthStore authStore = null, WebProxy proxy = null) { Proxy = proxy; ClientId = clientId; ClientSecret = clientSecret; if (authStore != null) { AuthStore = authStore; } else { AuthStore = new NullAuthStore(); } OAuthInfo = AuthStore.Get(); }
public LoginIntegrationTests() { DbCreator.Create(); conn = DbConnectionFactory.CreateAndOpen(DbCreator.TestInstance, TestDb); var config = new Config { Database = TestDb, Server = DbCreator.TestInstance }; userId = DbCreator.CreateUser(config, TestUser, TestTwoFactorCode, TestVerificationPath); var authStore = new AuthStore(config); _authService = new AuthenticationService(authStore); }
/// <summary> /// Authenticates the specified grant type. /// </summary> /// <param name="grantType">Type of the grant.</param> /// <param name="attributes">The attributes.</param> /// <returns>PodioOAuth.</returns> private async Task <PodioOAuth> AuthenticateAsync(string grantType, Dictionary <string, string> attributes) { attributes["client_id"] = ClientId; attributes["client_secret"] = ClientSecret; var options = new Dictionary <string, object>() { { "oauth_request", true } }; PodioOAuth podioOAuth = await PostAsync <PodioOAuth>("/oauth/token", attributes, options); this.OAuth = podioOAuth; AuthStore.Set(podioOAuth); return(podioOAuth); }
/// <summary> /// Internals the constructor. /// </summary> /// <param name="clientId">The client identifier.</param> /// <param name="clientSecret">The client secret.</param> /// <param name="authStore">The authentication store.</param> private void internalConstructor(string clientId, string clientSecret, IAuthStore authStore) { ClientId = clientId; ClientSecret = clientSecret; ApiUrl = "https://api.podio.com:443"; if (authStore != null) { AuthStore = authStore; } else { AuthStore = new NullAuthStore(); } OAuth = AuthStore.Get(); }
private OAuthInfo Authenticate(string grantType, Dictionary <string, string> attributes) { attributes["client_id"] = ClientId; attributes["client_secret"] = ClientSecret; Dictionary <string, object> options = null; options = new Dictionary <string, object>() { { "oauth_request", true } }; OAuthInfo OAuthInfo = requestHelper.Post <OAuthInfo>("/oauth/token", attributes, options); this.OAuthInfo = OAuthInfo; AuthStore.Set(OAuthInfo); return(OAuthInfo); }
/// <summary> /// Remove the Authenticate. /// </summary> public void DeAuthenticate() { AuthStore.Set(null); }
public RequireLoginFilter(OneContext context, AuthStore store, SecretStore secretStore) { Context = context; Store = store; SecretStore = secretStore; }
protected override void OnSleep() { // Handle when your app sleeps AuthStore.DetachListener(); }
public GroupManageController(AuthStore authStore, OneContext context) { AuthStore = authStore; Context = context; }
public AccessController(OneContext context, AuthStore store, SecretStore secretStore) { Context = context; Store = store; this.secretStore = secretStore; }
public CommentsController(AuthStore authStore, OneContext context) { AuthStore = authStore; Context = context; }
public AuthenticationMiddleware(OneContext context, AuthStore store, SecretStore secretStore) { Context = context; Store = store; SecretStore = secretStore; }