GitHubProvider

class gafaelfawr.providers.github.GitHubProvider(*, config, http_client, logger)

Bases: Provider

Authenticate a user with GitHub.

Parameters:
  • config (GitHubConfig) – Configuration for the GitHub authentication provider.

  • http_client (AsyncClient) – Session to use to make HTTP requests.

  • logger (BoundLogger) – Logger for any log messages.

Methods Summary

create_user_info(code, state, session)

Given the code from an authentication, create the user information.

get_redirect_url(state)

Get the login URL to which to redirect the user.

logout(session)

Revoke the OAuth authorization grant for this user.

Methods Documentation

async create_user_info(code, state, session)

Given the code from an authentication, create the user information.

The GitHub access token is stored in the github field of the state parameter so that it can be used during logout.

Parameters:
  • code (str) – Code returned by a successful authentication.

  • state (str) – The same random string used for the redirect URL.

  • session (State) – The session state, used to store the GitHub access token.

Returns:

The user information corresponding to that authentication.

Return type:

TokenUserInfo

Raises:
  • GitHubError – Raised if GitHub responded with an error to a request.

  • GitHubWebError – Raised if an HTTP client error occurred trying to talk to GitHub.

  • PermissionDeniedError – Raised if the GitHub username is not a valid username for Gafaelfawr.

get_redirect_url(state)

Get the login URL to which to redirect the user.

Parameters:

state (str) – A random string used for CSRF protection.

Returns:

The encoded URL to which to redirect the user.

Return type:

str

async logout(session)

Revoke the OAuth authorization grant for this user.

During logout, revoke the user’s OAuth authorization. This ensures that, after an explicit logout, logging in again forces a reauthorization and thus an update of the granted information.

Parameters:

session (State) – The session state, which contains the GitHub access token.

Return type:

None