Class: Simple::OAuth2::Strategies::Base

Inherits:
Object
  • Object
show all
Defined in:
lib/simple_oauth2/strategies/base.rb

Overview

Base Strategies class. Contains common functionality for all the descendants

Class Method Summary collapse

Class Method Details

.authenticate_access_grant(request) ⇒ Object

Authenticates Access Grant from the request


24
25
26
# File 'lib/simple_oauth2/strategies/base.rb', line 24

def authenticate_access_grant(request)
  config.access_grant_class.authenticate(request.code)
end

.authenticate_client(request) ⇒ Object

Authenticates Client from the request


10
11
12
# File 'lib/simple_oauth2/strategies/base.rb', line 10

def authenticate_client(request)
  config.client_class.authenticate(request.client_id)
end

.authenticate_resource_owner(client, request) ⇒ Object

Authenticates Resource Owner from the request


15
16
17
18
19
20
21
# File 'lib/simple_oauth2/strategies/base.rb', line 15

def authenticate_resource_owner(client, request)
  config.resource_owner_class.oauth_authenticate(
    client,
    request.params['username'],
    request.params['password']
  )
end

.authorization_verify_client!(request, response) ⇒ Object

Authorization endpoint, check client and redirect_uri for exact matching verifier


45
46
47
48
49
# File 'lib/simple_oauth2/strategies/base.rb', line 45

def authorization_verify_client!(request, response)
  client = authenticate_client(request) || request.bad_request!
  response.redirect_uri = request.verify_redirect_uri!(client.redirect_uri)
  client
end

.expose_to_bearer_token(token) ⇒ Rack::OAuth2::AccessToken::Bearer

Exposes token object to Bearer token.

Parameters:

  • token (AccessToken)

    any object that responds to `to_bearer_token`

Returns:

  • (Rack::OAuth2::AccessToken::Bearer)

    bearer token instance


33
34
35
# File 'lib/simple_oauth2/strategies/base.rb', line 33

def expose_to_bearer_token(token)
  Rack::OAuth2::AccessToken::Bearer.new(token.to_bearer_token)
end

.token_verify_client!(request) ⇒ Object

Token endpoint, check client for exact matching verifier


38
39
40
41
42
# File 'lib/simple_oauth2/strategies/base.rb', line 38

def token_verify_client!(request)
  client = authenticate_client(request) || request.invalid_client!
  client.secret == request.client_secret || request.invalid_client!
  client
end