Beispiel #1
0
        public void saveToken(AuthToken token)
        {
            clearTokens ();

            var newAccount = new Account ();
            newAccount.Username = token.accessToken;
            if (token.expiresIn != null) { newAccount.Properties.Add ("exires_in", token.expiresIn); }
            if (token.tokenType != null) { newAccount.Properties.Add ("token_type", token.tokenType); }
            if (token.scope != null) { newAccount.Properties.Add ("scope", token.scope); }
            if (token.refreshToken != null) { newAccount.Properties.Add ("refresh_token", token.refreshToken); }
            store.Save (newAccount, context);
        }
Beispiel #2
0
        private void LoadAccessToken()
        {
            var token = DependencyService.Get<ITokenStore>().getToken();

            if (token != null)
            {
                AuthToken = token;
                RefreshPushToken();
                MessagingCenter.Send(Current, "refresh_menu");
            }
            else
            {
                ShowLogin();
            }
        }
Beispiel #3
0
        public AuthToken getToken()
        {
            var account = store.FindAccountsForService (context).FirstOrDefault ();

            if (account == null) {
                return null;
            } else {
                var token = new AuthToken();
                token.accessToken = account.Username;

                if (account.Properties.ContainsKey("expires_in")) { token.expiresIn = account.Properties ["expires_in"]; }
                if (account.Properties.ContainsKey("token_type")) { token.tokenType = account.Properties ["token_type"]; }
                if (account.Properties.ContainsKey("scope")) { token.scope = account.Properties ["scope"]; }
                if (account.Properties.ContainsKey("refresh_token")) { token.refreshToken = account.Properties ["refresh_token"]; }
                return token;
            }
        }
Beispiel #4
0
		public async Task<AuthToken> RefreshToken(AuthToken currentToken)
		{
			var uri = new Uri (Constants.Url + "oauth/v2/token");
			var formContent = new FormUrlEncodedContent (new [] {
				new KeyValuePair<string,string>("client_id", Constants.ClientId),
				new KeyValuePair<string,string>("client_secret", Constants.ClientSecret),
				new KeyValuePair<string,string>("grant_type", "refresh_token"),
				new KeyValuePair<string,string>("refresh_token", currentToken.refreshToken),
			});

			var response = await client.PostAsync (uri, formContent);
			var content = await response.Content.ReadAsStringAsync ();

			if (response.IsSuccessStatusCode) {
				System.Diagnostics.Debug.WriteLine ("Refresh token succesful: " + content);
				return JsonConvert.DeserializeObject <AuthToken> (content);
			} else {
				System.Diagnostics.Debug.WriteLine ("A problem occured during token refresh, triggering relogin: "******"trigger_login");
				return null;
			}

		}
Beispiel #5
0
        private void UpdateToken(AuthToken newToken, ITokenStore store)
        {
            AuthToken = newToken;
            CurrentSite = MainSite;
            WebService = new WebService();

            store.saveToken(newToken);

            MessagingCenter.Send(Current, "login_succesful");
            MessagingCenter.Send(Current, "refresh_menu");
        }