ElixirAuthGoogle (elixir_auth_google v1.6.3)

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

generate_redirect_uri/1 generates the Google redirect uri based on conn

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: https://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

Specs

conn() :: map()

Link to this section Functions

Link to this function

generate_oauth_url(conn)

Specs

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)

Same as generate_oauth_url/1 with state query parameter

Link to this function

generate_redirect_uri(conn)

Specs

generate_redirect_uri(conn()) :: String.t()

generate_redirect_uri/1 generates the Google redirect uri based on conn

Link to this function

get_baseurl_from_conn(map)

Specs

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)

Specs

get_token(String.t(), conn()) :: {: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)

Specs

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

inject_poison()

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

Link to this function

parse_body_response(arg)

Specs

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.