Exemple #1
0
        /// <summary>
        /// Requests a PoP token using an authorization code.
        /// </summary>
        /// <param name="client">The client.</param>
        /// <param name="code">The code.</param>
        /// <param name="redirectUri">The redirect URI.</param>
        /// <param name="codeVerifier">The code verifier.</param>
        /// <param name="algorithm">The algorithm.</param>
        /// <param name="key">The key.</param>
        /// <param name="extra">Extra parameters.</param>
        /// <param name="cancellationToken">The cancellation token.</param>
        /// <returns></returns>
        public static Task <TokenResponse> RequestAuthorizationCodePopAsync(this TokenClient client, string code, string redirectUri, string codeVerifier = null, string algorithm = null, string key = null, object extra = null, CancellationToken cancellationToken = default(CancellationToken))
        {
            var fields = new Dictionary <string, string>
            {
                { OidcConstants.TokenRequest.TokenType, OidcConstants.TokenRequestTypes.Pop },
                { OidcConstants.TokenRequest.GrantType, OidcConstants.GrantTypes.AuthorizationCode },
                { OidcConstants.TokenRequest.Code, code },
                { OidcConstants.TokenRequest.RedirectUri, redirectUri }
            };

            if (!string.IsNullOrWhiteSpace(codeVerifier))
            {
                fields.Add(OidcConstants.TokenRequest.CodeVerifier, codeVerifier);
            }

            if (!string.IsNullOrWhiteSpace(algorithm))
            {
                fields.Add(OidcConstants.TokenRequest.Algorithm, algorithm);
            }

            if (!string.IsNullOrWhiteSpace(key))
            {
                fields.Add(OidcConstants.TokenRequest.Key, key);
            }

            return(client.RequestAsync(Merge(client, fields, extra), cancellationToken));
        }
Exemple #2
0
        /// <summary>
        /// Requests a token using a refresh token.
        /// </summary>
        /// <param name="client">The client.</param>
        /// <param name="refreshToken">The refresh token.</param>
        /// <param name="extra">Extra parameters.</param>
        /// <param name="cancellationToken">The cancellation token.</param>
        /// <returns></returns>
        public static Task <TokenResponse> RequestRefreshTokenAsync(this TokenClient client, string refreshToken, object extra = null, CancellationToken cancellationToken = default(CancellationToken))
        {
            var fields = new Dictionary <string, string>
            {
                { OidcConstants.TokenRequest.GrantType, OidcConstants.GrantTypes.RefreshToken },
                { OidcConstants.TokenRequest.RefreshToken, refreshToken }
            };

            return(client.RequestAsync(Merge(client, fields, extra), cancellationToken));
        }
Exemple #3
0
        /// <summary>
        /// Requests a token based on client credentials.
        /// </summary>
        /// <param name="client">The client.</param>
        /// <param name="scope">The scope.</param>
        /// <param name="extra">Extra parameters.</param>
        /// <param name="cancellationToken">The cancellation token.</param>
        /// <returns></returns>
        public static Task <TokenResponse> RequestClientCredentialsAsync(this TokenClient client, string scope = null, object extra = null, CancellationToken cancellationToken = default(CancellationToken))
        {
            var fields = new Dictionary <string, string>
            {
                { OidcConstants.TokenRequest.GrantType, OidcConstants.GrantTypes.ClientCredentials }
            };

            fields.AddIfPresent(OidcConstants.TokenRequest.Scope, scope);

            return(client.RequestAsync(client.Merge(fields, extra), cancellationToken));
        }
Exemple #4
0
        public static Task <TokenResponse> RequestAuthorizationCodeAsync(this TokenClient client, string code, string redirectUri, object extra = null, CancellationToken cancellationToken = default(CancellationToken))
        {
            var fields = new Dictionary <string, string>
            {
                { OAuth2Constants.GrantType, OAuth2Constants.GrantTypes.AuthorizationCode },
                { OAuth2Constants.Code, code },
                { OAuth2Constants.RedirectUri, redirectUri }
            };

            return(client.RequestAsync(Merge(client, fields, extra), cancellationToken));
        }
Exemple #5
0
        /// <summary>
        /// Requests a token using an authorization code.
        /// </summary>
        /// <param name="client">The client.</param>
        /// <param name="code">The code.</param>
        /// <param name="redirectUri">The redirect URI.</param>
        /// <param name="codeVerifier">The code verifier.</param>
        /// <param name="extra">Extra parameters.</param>
        /// <param name="cancellationToken">The cancellation token.</param>
        /// <returns></returns>
        public static Task <TokenResponse> RequestAuthorizationCodeAsync(this TokenClient client, string code, string redirectUri, string codeVerifier = null, object extra = null, CancellationToken cancellationToken = default(CancellationToken))
        {
            var fields = new Dictionary <string, string>
            {
                { OidcConstants.TokenRequest.GrantType, OidcConstants.GrantTypes.AuthorizationCode },
                { OidcConstants.TokenRequest.Code, code },
                { OidcConstants.TokenRequest.RedirectUri, redirectUri }
            };

            fields.AddIfPresent(OidcConstants.TokenRequest.CodeVerifier, codeVerifier);

            return(client.RequestAsync(client.Merge(fields, extra), cancellationToken));
        }
Exemple #6
0
        /// <summary>
        /// Requests a token using the resource owner password credentials.
        /// </summary>
        /// <param name="client">The client.</param>
        /// <param name="userName">Name of the user.</param>
        /// <param name="password">The password.</param>
        /// <param name="scope">The scope.</param>
        /// <param name="extra">Extra parameters.</param>
        /// <param name="cancellationToken">The cancellation token.</param>
        /// <returns></returns>
        public static Task <TokenResponse> RequestResourceOwnerPasswordAsync(this TokenClient client, string userName, string password, string scope = null, object extra = null, CancellationToken cancellationToken = default(CancellationToken))
        {
            var fields = new Dictionary <string, string>
            {
                { OidcConstants.TokenRequest.GrantType, OidcConstants.GrantTypes.Password },
                { OidcConstants.TokenRequest.UserName, userName },
                { OidcConstants.TokenRequest.Password, password }
            };

            fields.AddIfPresent(OidcConstants.TokenRequest.Scope, scope);

            return(client.RequestAsync(client.Merge(fields, extra), cancellationToken));
        }
Exemple #7
0
        /// <summary>
        /// Requests a token based on client credentials.
        /// </summary>
        /// <param name="client">The client.</param>
        /// <param name="scope">The scope.</param>
        /// <param name="extra">Extra parameters.</param>
        /// <param name="cancellationToken">The cancellation token.</param>
        /// <returns></returns>
        public static Task <TokenResponse> RequestClientCredentialsAsync(this TokenClient client, string scope = null, object extra = null, CancellationToken cancellationToken = default(CancellationToken))
        {
            var fields = new Dictionary <string, string>
            {
                { OidcConstants.TokenRequest.GrantType, OidcConstants.GrantTypes.ClientCredentials }
            };

            if (!string.IsNullOrWhiteSpace(scope))
            {
                fields.Add(OidcConstants.TokenRequest.Scope, scope);
            }

            return(client.RequestAsync(Merge(client, fields, extra), cancellationToken));
        }
        /// <summary>Requests a token using a custom grant.</summary>
        /// <param name="client">The client.</param>
        /// <param name="grantType">Type of the grant.</param>
        /// <param name="scope">The scope.</param>
        /// <param name="extra">Extra parameters.</param>
        /// <param name="cancellationToken">The cancellation token.</param>
        /// <returns></returns>
        public static Task <TokenResponse> RequestCustomGrantAsync(this TokenClient client, string grantType, string scope = null, object extra = null, CancellationToken cancellationToken = default(CancellationToken))
        {
            var fields = new Dictionary <string, string>(StringComparer.Ordinal)
            {
                { OidcConstants.TokenRequest.GrantType, grantType }
            };

            if (!string.IsNullOrWhiteSpace(scope))
            {
                fields.Add(OidcConstants.TokenRequest.Scope, scope);
            }

            return(client.RequestAsync(Merge(client, fields, extra), cancellationToken));
        }
Exemple #9
0
        public static Task <TokenResponse> RequestAssertionAsync(this TokenClient client, string assertionType, string assertion, string scope = null, object extra = null, CancellationToken cancellationToken = default(CancellationToken))
        {
            var fields = new Dictionary <string, string>
            {
                { OAuth2Constants.GrantType, assertionType },
                { OAuth2Constants.Assertion, assertion },
            };

            if (!string.IsNullOrWhiteSpace(scope))
            {
                fields.Add(OAuth2Constants.Scope, scope);
            }

            return(client.RequestAsync(Merge(client, fields, extra), cancellationToken));
        }
Exemple #10
0
        public static Task <TokenResponse> RequestResourceOwnerPasswordAsync(this TokenClient client, string userName, string password, string scope = null, object extra = null, CancellationToken cancellationToken = default(CancellationToken))
        {
            var fields = new Dictionary <string, string>
            {
                { OAuth2Constants.GrantType, OAuth2Constants.GrantTypes.Password },
                { OAuth2Constants.UserName, userName },
                { OAuth2Constants.Password, password }
            };

            if (!string.IsNullOrWhiteSpace(scope))
            {
                fields.Add(OAuth2Constants.Scope, scope);
            }

            return(client.RequestAsync(Merge(client, fields, extra), cancellationToken));
        }
        /// <summary>Requests a token using an authorization code.</summary>
        /// <param name="client">The client.</param>
        /// <param name="code">The code.</param>
        /// <param name="redirectUri">The redirect URI.</param>
        /// <param name="codeVerifier">The code verifier.</param>
        /// <param name="extra">Extra parameters.</param>
        /// <param name="cancellationToken">The cancellation token.</param>
        /// <returns></returns>
        public static Task <TokenResponse> RequestAuthorizationCodeAsync(this TokenClient client, string code, string redirectUri, string codeVerifier = null, object extra = null, CancellationToken cancellationToken = default(CancellationToken))
        {
            var fields = new Dictionary <string, string>(StringComparer.Ordinal)
            {
                { OidcConstants.TokenRequest.GrantType, OidcConstants.GrantTypes.AuthorizationCode },
                { OidcConstants.TokenRequest.Code, code },
                { OidcConstants.TokenRequest.RedirectUri, redirectUri }
            };

            if (!string.IsNullOrWhiteSpace(codeVerifier))
            {
                fields.Add(OidcConstants.TokenRequest.CodeVerifier, codeVerifier);
            }

            return(client.RequestAsync(Merge(client, fields, extra), cancellationToken));
        }
Exemple #12
0
        /// <summary>
        /// Requests a PoP token using a refresh token.
        /// </summary>
        /// <param name="client">The client.</param>
        /// <param name="refreshToken">The refresh token.</param>
        /// <param name="algorithm">The algorithm.</param>
        /// <param name="key">The key.</param>
        /// <param name="extra">Extra parameters.</param>
        /// <param name="cancellationToken">The cancellation token.</param>
        /// <returns></returns>
        public static Task <TokenResponse> RequestRefreshTokenPopAsync(this TokenClient client, string refreshToken, string algorithm = null, string key = null, object extra = null, CancellationToken cancellationToken = default(CancellationToken))
        {
            var fields = new Dictionary <string, string>
            {
                { OidcConstants.TokenRequest.TokenType, OidcConstants.TokenRequestTypes.Pop },
                { OidcConstants.TokenRequest.GrantType, OidcConstants.GrantTypes.RefreshToken },
                { OidcConstants.TokenRequest.RefreshToken, refreshToken }
            };

            if (!string.IsNullOrWhiteSpace(algorithm))
            {
                fields.Add(OidcConstants.TokenRequest.Algorithm, algorithm);
            }

            if (!string.IsNullOrWhiteSpace(key))
            {
                fields.Add(OidcConstants.TokenRequest.Key, key);
            }

            return(client.RequestAsync(Merge(client, fields, extra), cancellationToken));
        }
Exemple #13
0
 /// <summary>
 /// Requests a token using a custom request
 /// </summary>
 /// <param name="client">The client.</param>
 /// <param name="values">The values.</param>
 /// <param name="cancellationToken">The cancellation token.</param>
 /// <returns></returns>
 public static Task <TokenResponse> RequestCustomAsync(this TokenClient client, object values, CancellationToken cancellationToken = default(CancellationToken))
 {
     return(client.RequestAsync(Merge(client, ObjectToDictionary(values)), cancellationToken));
 }