GetTokenPostData() public méthode

public GetTokenPostData ( string clientSecret ) : string>>.Task
clientSecret string
Résultat string>>.Task
Exemple #1
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 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);
        }
Exemple #2
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);
        }
Exemple #3
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;
		}