Assent.Strategy.Google (Assent v0.4.0)

Copy Markdown View Source

Google OpenID Connect strategy.

In the normalized user response a hd ("Hosted Domain") field is included in user parameters and can be used to limit access to users belonging to a particular hosted domain.

Usage

config = [
  client_id: "REPLACE_WITH_CLIENT_ID",
  client_secret: "REPLACE_WITH_CLIENT_SECRET",
  redirect_uri: "http://localhost:4000/auth/callback"
]

To get the refresh token, it's necessary to pass access_type: "offline" in the authorization request:

config = [
  client_id: "REPLACE_WITH_CLIENT_ID",
  client_secret: "REPLACE_WITH_CLIENT_SECRET",
  authorization_params: [
    access_type: "offline",
    scope: "email profile"
  ]
]

See Assent.Strategy.OIDC for more.

Summary

Functions

Generates an OpenID Connect authorization URL.

Handles an OpenID Connect callback.

Fetches user data from an ID Token or the UserInfo endpoint.

Returns user claims without provider-specific normalization.

Functions

authorize_url(config)

@spec authorize_url(Keyword.t()) :: Assent.Strategy.OIDC.on_authorize_url()

Generates an OpenID Connect authorization URL.

callback(config, params)

@spec callback(Keyword.t(), map()) :: Assent.Strategy.OIDC.on_callback()

Handles an OpenID Connect callback.

fetch_user(config, token)

@spec fetch_user(Keyword.t(), map()) :: {:ok, map()} | {:error, term()}

Fetches user data from an ID Token or the UserInfo endpoint.

normalize(config, user)

Returns user claims without provider-specific normalization.