Module: OAuth::AccessTokenValidationService

Defined in:
app/services/oauth/access_token_validation_service.rb

Overview

Constant Summary collapse

VALID =

Results:

:valid
EXPIRED =
:expired
REVOKED =
:revoked
INSUFFICIENT_TOKEN_SCOPE =
:insufficient_token_scope

Class Method Summary collapse

Class Method Details

.validate(token, scopes: []) ⇒ Object


11
12
13
14
15
16
17
18
19
20
21
22
23
24
# File 'app/services/oauth/access_token_validation_service.rb', line 11

def validate(token, scopes: [])
  if token.expired?
    return EXPIRED

  elsif token.revoked?
    return REVOKED

  elsif !self.sufficent_scope?(token, scopes)
    return INSUFFICIENT_TOKEN_SCOPE

  else
    return VALID
  end
end

.validate!(token, scopes: []) ⇒ Object


26
27
28
29
30
31
32
33
34
35
36
37
38
# File 'app/services/oauth/access_token_validation_service.rb', line 26

def validate!(token, scopes: [])
  case validate(token, scopes: scopes)

  when INSUFFICIENT_TOKEN_SCOPE
    fail OAuth::InsufficientTokenScopeError, scopes

  when EXPIRED
    fail OAuth::ExpiredTokenError

  when REVOKED
    fail OAuth::RevokedTokenError
  end
end