Exemplo n.º 1
0
        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);
        }
Exemplo n.º 2
0
        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;
        }
Exemplo n.º 3
0
        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);
        }
Exemplo n.º 4
0
 protected override async Task OnInitAsync()
 {
     if (!await AuthStore.GetAccessToken())
     {
         UriHelper.NavigateTo("/login");
         return;
     }
 }
Exemplo n.º 5
0
        public async Task LogoutAsync()
        {
            LoginManager.Instance.LogOut();

            CookieManager.Instance.RemoveAllCookie();
            AuthStore.DeleteTokenCache();
            await App.Instance.MobileService.LogoutAsync();
        }
Exemplo n.º 6
0
        public async Task LogoutAsync()
        {
            foreach (var cookie in NSHttpCookieStorage.SharedStorage.Cookies)
            {
                NSHttpCookieStorage.SharedStorage.DeleteCookie(cookie);
            }

            AuthStore.DeleteTokenCache();
            await App.Instance.MobileService.LogoutAsync();
        }
Exemplo n.º 7
0
        private MobileServiceUser GetCachedUser()
        {
            var user = AuthStore.GetUserFromCache();

            if (user != null)
            {
                App.Instance.MobileService.CurrentUser = user;
            }

            return(user);
        }
Exemplo n.º 8
0
        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);
        }
Exemplo n.º 9
0
        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();
        }
Exemplo n.º 11
0
        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);
        }
Exemplo n.º 12
0
        /// <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);
        }
Exemplo n.º 13
0
        /// <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);
        }
Exemplo n.º 15
0
 /// <summary>
 /// Remove the Authenticate.
 /// </summary>
 public void DeAuthenticate()
 {
     AuthStore.Set(null);
 }
Exemplo n.º 16
0
 public RequireLoginFilter(OneContext context, AuthStore store, SecretStore secretStore)
 {
     Context     = context;
     Store       = store;
     SecretStore = secretStore;
 }
Exemplo n.º 17
0
 protected override void OnSleep()
 {
     // Handle when your app sleeps
     AuthStore.DetachListener();
 }
Exemplo n.º 18
0
 public GroupManageController(AuthStore authStore, OneContext context)
 {
     AuthStore = authStore;
     Context   = context;
 }
Exemplo n.º 19
0
 public AccessController(OneContext context, AuthStore store, SecretStore secretStore)
 {
     Context          = context;
     Store            = store;
     this.secretStore = secretStore;
 }
Exemplo n.º 20
0
 public CommentsController(AuthStore authStore, OneContext context)
 {
     AuthStore = authStore;
     Context   = context;
 }
Exemplo n.º 21
0
 public AuthenticationMiddleware(OneContext context, AuthStore store, SecretStore secretStore)
 {
     Context     = context;
     Store       = store;
     SecretStore = secretStore;
 }