Ejemplo n.º 1
0
        protected virtual async Task <OAuthAccount> GetAccountFromAuthCode(Authenticator authenticator, string identifier)
        {
            var postData = await authenticator.GetTokenPostData(ClientSecret);

            if (string.IsNullOrWhiteSpace(TokenUrl))
            {
                throw new Exception("Invalid TokenURL");
            }
            var reply = await Client.PostAsync(TokenUrl, new FormUrlEncodedContent(postData));

            var resp = await reply.Content.ReadAsStringAsync();

            var result = Deserialize <OauthResponse>(resp);

            if (!string.IsNullOrEmpty(result.Error))
            {
                throw new Exception(result.ErrorDescription);
            }

            var account = new OAuthAccount()
            {
                ExpiresIn    = result.ExpiresIn,
                Created      = DateTime.UtcNow,
                RefreshToken = result.RefreshToken,
                Scope        = authenticator.Scope.ToArray(),
                TokenType    = result.TokenType,
                Token        = result.AccessToken,
                ClientId     = ClientId,
                Identifier   = identifier,
            };

            return(account);
        }
Ejemplo n.º 2
0
		protected override Task<OAuthAccount> GetAccountFromAuthCode (WebAuthenticator authenticator, string identifier)
		{
			var auth = authenticator as OAuthPasswordAuthenticator;
			var account = new OAuthAccount () {
				ExpiresIn = auth.Token.ExpiresIn,
				Created = DateTime.UtcNow,
				RefreshToken = auth.Token.RefreshToken,
				Scope = authenticator.Scope?.ToArray (),
				TokenType = auth.Token.TokenType,
				Token = auth.Token.AccessToken,
				ClientId = ClientId,
				Identifier = identifier,
			};
			return Task.FromResult (account);
		}
Ejemplo n.º 3
0
        protected override Task <OAuthAccount> GetAccountFromAuthCode(WebAuthenticator authenticator, string identifier)
        {
            var auth    = authenticator as OAuthPasswordAuthenticator;
            var account = new OAuthAccount()
            {
                ExpiresIn    = auth.Token.ExpiresIn,
                Created      = DateTime.UtcNow,
                RefreshToken = auth.Token.RefreshToken,
                Scope        = authenticator.Scope?.ToArray(),
                TokenType    = auth.Token.TokenType,
                Token        = auth.Token.AccessToken,
                ClientId     = ClientId,
                Identifier   = identifier,
            };

            return(Task.FromResult(account));
        }
Ejemplo n.º 4
0
        protected virtual async Task <OAuthAccount> GetAccountFromAuthCode(WebAuthenticator authenticator, string identifier)
        {
            var postData = await authenticator.GetTokenPostData(ClientSecret);

            if (string.IsNullOrWhiteSpace(TokenUrl))
            {
                throw new Exception("Invalid TokenURL");
            }
            var message = new HttpRequestMessage(HttpMethod.Post, TokenUrl)
            {
                Content = new FormUrlEncodedContent(postData),
                Headers =
                {
                    { "Accept", "application/json" }
                }
            };
            var reply = await Client.SendAsync(message);

            var resp = await reply.Content.ReadAsStringAsync();

            var result = Deserialize <OauthResponse> (resp);

            if (!string.IsNullOrEmpty(result?.Error))
            {
                throw new Exception($"{result.Error} : {result.ErrorDescription}");
            }
            reply.EnsureSuccessStatusCode();
            var account = new OAuthAccount()
            {
                ExpiresIn    = result.ExpiresIn,
                Created      = DateTime.UtcNow,
                RefreshToken = result.RefreshToken,
                Scope        = authenticator.Scope?.ToArray(),
                TokenType    = result.TokenType,
                Token        = result.AccessToken,
                ClientId     = ClientId,
                Identifier   = identifier,
                Cookies      = authenticator.Cookies,
                IdToken      = result.Id
            };

            return(account);
        }
Ejemplo n.º 5
0
		protected virtual async Task<OAuthAccount> GetAccountFromAuthCode(WebAuthenticator authenticator, string identifier)
		{
			var postData = await authenticator.GetTokenPostData(ClientSecret);
			if (string.IsNullOrWhiteSpace(TokenUrl))
				throw new Exception("Invalid TokenURL");
			var message = new HttpRequestMessage (HttpMethod.Post, TokenUrl) {
				Content = new FormUrlEncodedContent (postData),
				Headers = {
					{"Accept","application/json"}
				}
			};
			var reply = await Client.SendAsync (message);
			var resp = await reply.Content.ReadAsStringAsync();
			var result = Deserialize<OauthResponse>(resp);
			if (!string.IsNullOrEmpty(result?.Error))
 				throw new Exception(result.ErrorDescription);

			var account = new OAuthAccount () {
				ExpiresIn = result.ExpiresIn,
				Created = DateTime.UtcNow,
				RefreshToken = result.RefreshToken,
				Scope = authenticator.Scope?.ToArray (),
				TokenType = result.TokenType,
				Token = result.AccessToken,
				ClientId = ClientId,
				Identifier = identifier,
				Cookies = authenticator.Cookies,
			};
			return account;
		}
Ejemplo n.º 6
0
		protected virtual async Task<OAuthAccount> GetAccountFromAuthCode(Authenticator authenticator, string identifier)
		{
			var postData = await authenticator.GetTokenPostData(ClientSecret);
			if (string.IsNullOrWhiteSpace(TokenUrl))
				throw new Exception("Invalid TokenURL");
			var reply = await Client.PostAsync(TokenUrl, new FormUrlEncodedContent(postData));
			var resp = await reply.Content.ReadAsStringAsync();
			var result = Deserialize<OauthResponse>(resp);
			if (!string.IsNullOrEmpty(result.Error))
 				throw new Exception(result.ErrorDescription);

			var account = new OAuthAccount()
			{
				ExpiresIn = result.ExpiresIn,
				Created = DateTime.UtcNow,
				RefreshToken = result.RefreshToken,
				Scope = authenticator.Scope.ToArray(),
				TokenType = result.TokenType,
				Token = result.AccessToken,
				ClientId = ClientId,
				Identifier = identifier,
			};
			return account;
		}
		protected override async Task<OAuthAccount> GetAccountFromAuthCode(Authenticator authenticator, string identifier)
		{
			var account = new OAuthAccount()
			{
				ExpiresIn = (long)(TimeSpan.FromDays(365).TotalSeconds),
				Created = DateTime.UtcNow,
				TokenType = "Bearer",
				Token = authenticator.AuthCode,
				ClientId = ClientId,
				Identifier = identifier,
			};
			return account;
		}