Module: Core::Helpers::Tokens

Included in:
Controllers::Base
Defined in:
lib/core/helpers/tokens.rb

Overview

This helper aims at providing vanity methods concerning OAuth tokens.

Author:

Instance Method Summary collapse

Instance Method Details

#tokenCore::Models::Oauth::AccessToken

Returns the database object representing the current OAuth token, or raises an error if the token seems to be invalid for any reason.

Returns:

  • (Core::Models::Oauth::AccessToken)

    the token if everything went well.

Raises:



16
17
18
19
20
21
22
23
24
25
# File 'lib/core/helpers/tokens.rb', line 16

def token
  return @token unless @token.nil?

  check_presence 'token'
  @token = Core::Models::OAuth::AccessToken.find_by(value: params['token'])
  api_not_found 'token.unknown' if @token.nil?
  token_app_id = token.authorization.application.id.to_s
  api_forbidden 'token.mismatch' if token_app_id != application.id.to_s
  @token
end