ElixirAuthGoogle (elixir_auth_google v1.6.9)

Minimalist Google OAuth Authentication for Elixir Apps. Extensively tested, documented, maintained and in active use in production.

Link to this section Summary

Functions

generate_oauth_url/1 creates the Google OAuth2 URL with client_id, scope and redirect_uri which is the URL Google will redirect to when auth is successful. This is the URL you need to use for your "Login with Google" button. See step 5 of the instructions.

Same as generate_oauth_url/1 with state query parameter, or a map of key/pair values to be included in the urls query string.

generate_redirect_uri/1 generates the Google redirect uri based on conn or the url. If the App.Endpoint.url() e.g: auth.dwyl.com or https://gcal.fly.dev is passed into generate_redirect_uri/1, return that url with the callback appended to it. See: github.com/dwyl/elixir-auth-google/issues/94

get_baseurl_from_conn/1 derives the base URL from the conn struct

get_token/2 encodes the secret keys and authorization code returned by Google and issues an HTTP request to get a person's profile data.

get_user_profile/1 requests the Google User's userinfo profile data providing the access_token received in the get_token/1 above. invokes parse_body_response/1 to decode the JSON data.

inject_poison/0 injects a TestDouble of HTTPoison in Test so that we don't have duplicate mock in consuming apps. see: github.com/dwyl/elixir-auth-google/issues/35

parse_body_response/1 parses the response returned by Google so your app can use the resulting JSON.

Link to this section Types

@type conn() :: map()
@type url() :: String.t()

Link to this section Functions

Link to this function

generate_oauth_url(url)

@spec generate_oauth_url(String.t()) :: String.t()
@spec generate_oauth_url(conn()) :: String.t()

generate_oauth_url/1 creates the Google OAuth2 URL with client_id, scope and redirect_uri which is the URL Google will redirect to when auth is successful. This is the URL you need to use for your "Login with Google" button. See step 5 of the instructions.

Link to this function

generate_oauth_url(conn, state)

@spec generate_oauth_url(conn(), String.t() | map()) :: String.t()

Same as generate_oauth_url/1 with state query parameter, or a map of key/pair values to be included in the urls query string.

Link to this function

generate_redirect_uri(url)

@spec generate_redirect_uri(url()) :: String.t()
@spec generate_redirect_uri(conn()) :: String.t()

generate_redirect_uri/1 generates the Google redirect uri based on conn or the url. If the App.Endpoint.url() e.g: auth.dwyl.com or https://gcal.fly.dev is passed into generate_redirect_uri/1, return that url with the callback appended to it. See: github.com/dwyl/elixir-auth-google/issues/94

Link to this function

get_baseurl_from_conn(conn)

@spec get_baseurl_from_conn(conn()) :: String.t()

get_baseurl_from_conn/1 derives the base URL from the conn struct

Link to this function

get_token(code, conn)

@spec get_token(String.t(), conn()) :: {:ok, map()} | {:error, any()}
@spec get_token(String.t(), url()) :: {:ok, map()} | {:error, any()}

get_token/2 encodes the secret keys and authorization code returned by Google and issues an HTTP request to get a person's profile data.

TODO: we still need to handle the various failure conditions >> issues/16

Link to this function

get_user_profile(token)

@spec get_user_profile(String.t()) :: {:ok, map()} | {:error, any()}

get_user_profile/1 requests the Google User's userinfo profile data providing the access_token received in the get_token/1 above. invokes parse_body_response/1 to decode the JSON data.

TODO: we still need to handle the various failure conditions >> issues/16 At this point the types of errors we expect are HTTP 40x/50x responses.

Link to this function

google_client_id()

Link to this function

inject_poison()

inject_poison/0 injects a TestDouble of HTTPoison in Test so that we don't have duplicate mock in consuming apps. see: github.com/dwyl/elixir-auth-google/issues/35

Link to this function

parse_body_response(arg)

@spec parse_body_response({atom(), String.t()} | {:error, any()}) ::
  {:ok, map()} | {:error, any()}

parse_body_response/1 parses the response returned by Google so your app can use the resulting JSON.