Module: GrapeTokenAuth::TokenValidationAPICore

Included in:
TokenValidationAPI
Defined in:
lib/grape_token_auth/apis/token_validation_api.rb

Overview

Contains the major functionality of TokenValidation

Class Method Summary collapse

Class Method Details

.included(base) ⇒ Object



5
6
7
8
9
10
11
12
13
14
15
16
# File 'lib/grape_token_auth/apis/token_validation_api.rb', line 5

def self.included(base)
  base.get '/validate_token' do
    token_authorizer = TokenAuthorizer.new(AuthorizerData.from_env(env))
    resource = token_authorizer.find_resource(base.resource_scope)
    if resource
      status 200
      present data: resource.token_validation_response
    else
      throw(:warden, 'errors' => 'Invalid login credentials')
    end
  end
end