ExFirebase v0.3.1 ExFirebase.Auth View Source
Firebase authentication interface
Link to this section Summary
Functions
Returns a cached access token
Makes an HTTP request for an OAuth2 access token using a service account’s credentials
Returns a cached public key by id
Makes an HTTP request to get Google’s public keys, whose private keys are used to sign Firebase Auth ID tokens
Returns cached public keys
Verifies the claims and signature of a Firebase Auth ID token
Link to this section Functions
Link to this function
access_token()
View Source
access_token() :: {:ok, String.t()} | {:error, ExFirebase.Error.t()}
Returns a cached access token
Examples
iex> ExFirebase.Auth.access_token()
{:ok, "1/8xbJqaOZXSUZbHLl5EOtu1pxz3fmmetKx9W8CV4t79M"}
Link to this function
get_access_token()
View Source
get_access_token() :: {:ok, HTTPoison.Response.t()} | {:error, HTTPoison.Error.t()} | {:error, ExFirebase.Error.t()}
Makes an HTTP request for an OAuth2 access token using a service account’s credentials
Examples
iex> ExFirebase.Auth.get_access_token()
{:ok,
%HTTPoison.Response{
body: %{
"access_token" => "1/8xbJqaOZXSUZbHLl5EOtu1pxz3fmmetKx9W8CV4t79M",
"expires_in" => 3600,
"token_type" => "Bearer"
},
...
status_code: 200
}}
Link to this function
get_public_key(key_id)
View Source
get_public_key(String.t()) :: {:ok, String.t()} | {:error, ExFirebase.Error.t()}
Returns a cached public key by id
Link to this function
get_public_keys()
View Source
get_public_keys() :: {:ok, HTTPoison.Response.t()} | {:error, HTTPoison.Error.t()}
Makes an HTTP request to get Google’s public keys, whose private keys are used to sign Firebase Auth ID tokens
Returns cached public keys
Link to this function
verify_token(token)
View Source
verify_token(String.t()) :: {:ok, JOSE.JWT.t()} | {:error, ExFirebase.Error.t()}
Verifies the claims and signature of a Firebase Auth ID token
Examples
iex> ExFirebase.Auth.verify_token("eyJhbGciOiJS...")
{:ok,
%JOSE.JWT{
fields: %{
"aud" => "project-id",
"auth_time" => 1540314428,
"exp" => 1540318028,
"firebase" => %{
"identities" => %{"phone" => ["+16505553434"]},
"sign_in_provider" => "phone"
},
"iat" => 1540314428,
"iss" => "https://securetoken.google.com/project-id",
"phone_number" => "+16505553434",
"sub" => "O5dHhHaWzsgUdNo6jIeTrWykPVd2",
"user_id" => "O5dHhHaWzsgUdNo6jIeTrWykPVd2"
}
}}