Struct oauth2::Client

source ·
pub struct Client<EF: ExtraTokenFields, TT: TokenType, TE: ErrorResponseType> { /* private fields */ }
Expand description

Stores the configuration for an OAuth2 client.

Implementations§

Initializes an OAuth2 client with the fields common to most OAuth2 flows.

Arguments
  • client_id - Client ID
  • client_secret - Optional client secret. A client secret is generally used for private (server-side) OAuth2 clients and omitted from public (client-side or native app) OAuth2 clients (see RFC 8252).
  • auth_url - Authorization endpoint: used by the client to obtain authorization from the resource owner via user-agent redirection. This URL is used in all standard OAuth2 flows except the Resource Owner Password Credentials Grant and the Client Credentials Grant.
  • token_url - Token endpoint: used by the client to exchange an authorization grant (code) for an access token, typically with client authentication. This URL is used in all standard OAuth2 flows except the Implicit Grant. If this value is set to None, the exchange_* methods will return Err(RequestTokenError::Other(_)).

Appends a new scope to the authorization URL.

Configures the type of client authentication used for communicating with the authorization server.

The default is to use HTTP Basic authentication, as recommended in Section 2.3.1 of RFC 6749.

Sets the the redirect URL used by the authorization endpoint.

Produces the full authorization URL used by the Authorization Code Grant flow, which is the most common OAuth2 flow.

Arguments
  • state_fn - A function that returns an opaque value used by the client to maintain state between the request and callback. The authorization server includes this value when redirecting the user-agent back to the client.
Security Warning

Callers should use a fresh, unpredictable state for each authorization request and verify that this value matches the state parameter passed by the authorization server to the redirect URI. Doing so mitigates Cross-Site Request Forgery attacks. To disable CSRF protections (NOT recommended), use insecure::authorize_url instead.

Produces the full authorization URL used by the Implicit Grant flow.

Arguments
  • state_fn - A function that returns an opaque value used by the client to maintain state between the request and callback. The authorization server includes this value when redirecting the user-agent back to the client.
Security Warning

Callers should use a fresh, unpredictable state for each authorization request and verify that this value matches the state parameter passed by the authorization server to the redirect URI. Doing so mitigates Cross-Site Request Forgery attacks. To disable CSRF protections (NOT recommended), use insecure::authorize_url_implicit instead.

Produces the full authorization URL used by an OAuth2 extension.

Arguments
  • response_type - The response type this client expects from the authorization endpoint. For "code" or "token" response types, instead use the authorize_url or authorize_url_implicit functions, respectively.
  • state_fn - A function that returns an opaque value used by the client to maintain state between the request and callback. The authorization server includes this value when redirecting the user-agent back to the client.
  • extra_params - Additional parameters as required by the applicable OAuth2 extension(s). Callers should NOT specify any of the following parameters: response_type, client_id, redirect_uri, or scope.
Security Warning

Callers should use a fresh, unpredictable state for each authorization request and verify that this value matches the state parameter passed by the authorization server to the redirect URI. Doing so mitigates Cross-Site Request Forgery attacks.

Callers should follow the security recommendations for any OAuth2 extensions used with this function, which are beyond the scope of RFC 6749.

Exchanges a code produced by a successful authorization process with an access token.

Acquires ownership of the code because authorization codes may only be used to retrieve an access token from the authorization server.

See https://tools.ietf.org/html/rfc6749#section-4.1.3

Exchanges a code produced by a successful authorization process with an access token.

Acquires ownership of the code because authorization codes may only be used to retrieve an access token from the authorization server.

See https://tools.ietf.org/html/rfc6749#section-4.1.3

Requests an access token for the password grant type.

See https://tools.ietf.org/html/rfc6749#section-4.3.2

Requests an access token for the client credentials grant type.

See https://tools.ietf.org/html/rfc6749#section-4.4.2

Exchanges a refresh token for an access token

See https://tools.ietf.org/html/rfc6749#section-6

Trait Implementations§

Returns a copy of the value. Read more
Performs copy-assignment from source. Read more
Formats the value using the given formatter. Read more

Auto Trait Implementations§

Blanket Implementations§

Gets the TypeId of self. Read more
Immutably borrows from an owned value. Read more
Mutably borrows from an owned value. Read more

Returns the argument unchanged.

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Should always be Self
The resulting type after obtaining ownership.
Creates owned data from borrowed data, usually by cloning. Read more
Uses borrowed data to replace owned data, usually by cloning. Read more
The type returned in the event of a conversion error.
Performs the conversion.
The type returned in the event of a conversion error.
Performs the conversion.