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
conn()
@type conn() :: map()
url()
@type url() :: String.t()
Link to this section Functions
generate_oauth_url(url)
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.
generate_oauth_url(conn, state)
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(url)
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(conn)
get_baseurl_from_conn/1
derives the base URL from the conn struct
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
get_user_profile(token)
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.
google_client_id()
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
parse_body_response(arg)
parse_body_response/1
parses the response returned by Google
so your app can use the resulting JSON.