gandalf v0.2.0 Gandalf.GrantType.Base

Base module for OAuth2 grant types

Summary

Functions

A common function for all Gandalf.GrantType to check if the client authorized for the given resource owner. Returns either true or false, depending on status of authorization

A common function to generate oauth2 tokens (access_token and refresh_token) for all Gandalf.GrantType

Functions

app_authorized?(user_id, client_id)

A common function for all Gandalf.GrantType to check if the client authorized for the given resource owner. Returns either true or false, depending on status of authorization.

Examples

Gandalf.GrantType.Base.app_authorized?(
  "256a6d70-4a91-43fe-aacf-5588862ed8a2"
  "52024ca6-cf1d-4a9d-bfb6-9bc5023ad56e"
)
create_oauth2_tokens(user_id, grant_type, client_id, scope, redirect_uri \\ nil)

A common function to generate oauth2 tokens (access_token and refresh_token) for all Gandalf.GrantType.

To create oauth2 tokens, function requires valid ‘resource owner model’, ‘grant_type’, ‘client_id’, ‘scope’ and as optional ‘redirect_uri’. It automatically checks given scopes against configuration scopes and if any invalid scope occurs then it raises an exception with type of Gandalf.Error.SuspiciousActivity. It automatically checks the refresh_token strategy from configuration params and creates if enabled, otherwise it skips creation.

Examples

Gandalf.GrantType.Base.create_oauth2_tokens(user, "refresh_token",
  "52024ca6-cf1d-4a9d-bfb6-9bc5023ad56e", "read",
  "http://localhost:4000/oauth2/callbacks")