gandalf v0.2.0 Gandalf.Authentication.Basic

Basic authentication helper module, implements Gandalf.Authentication behaviour.

Summary

Functions

Authenticates resource-owner using Basic Authentication header value

Functions

authenticate(auth_credentials, required_scopes)

Authenticates resource-owner using Basic Authentication header value.

It handles the decoding the ‘Authorization: Basic {auth_credentials}’ and matches resource owner with given email and password. Since Basic auth requires identity and password, it does not require any scope check for authorization. If any resource owner matched given credentials, it returns {:ok, Gandalf.User.Model struct}, otherwise {:error, Map, :http_status_code}

Examples

# Suppose we have a resource owner with
# email: foo@example.com and password: 12345678.
# Base 64 encoding of email:password combination will be
# 'Zm9vQGV4YW1wbGUuY29tOjEyMzQ1Njc4'. If we pass the encoded value
# to the function, it will return resource-owner
Gandalf.Authentication.Basic.authenticate(
  "Zm9vQGV4YW1wbGUuY29tOjEyMzQ1Njc4", [])

Gandalf.Authentication.Basic.authenticate(
  "Basic Zm9vQGV4YW1wbGUuY29tOjEyMzQ1Njc4", [])