elixir_auth_google v0.1.0 ElixirAuthGoogle

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/0 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_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.

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

Link to this section Functions

Link to this function

generate_oauth_url(conn)

generate_oauth_url(Map) :: String.t()

generate_oauth_url/0 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_redirect_uri(conn)

generate_redirect_uri(Map) :: String.t()

generate_redirect_uri/1 generates the Google redirect uri based on conn

Link to this function

get_baseurl_from_conn(conn)

get_baseurl_from_conn(Map) :: String.t()

get_baseurl_from_conn/1 derives the base URL from the conn struct

Link to this function

get_token(code, conn)

get_token(String.t(), Map) :: String.t()

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)

get_user_profile(String.t()) :: String.t()

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

parse_body_response(arg)

parse_body_response({atom(), String.t()}) :: String.t()

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