Class: PusherPlatform::Authenticator
- Inherits:
-
Object
- Object
- PusherPlatform::Authenticator
- Defined in:
- lib/pusher-platform/authenticator.rb
Instance Method Summary collapse
- #authenticate(auth_payload, options) ⇒ Object
- #authenticate_with_refresh_token(auth_payload, options) ⇒ Object
- #authenticate_with_refresh_token_and_request(request, options) ⇒ Object
- #authenticate_with_request(request, options) ⇒ Object
- #generate_access_token(options) ⇒ Object
-
#initialize(instance_id, key_id, key_secret) ⇒ Authenticator
constructor
A new instance of Authenticator.
Constructor Details
#initialize(instance_id, key_id, key_secret) ⇒ Authenticator
Returns a new instance of Authenticator.
10 11 12 13 14 |
# File 'lib/pusher-platform/authenticator.rb', line 10 def initialize(instance_id, key_id, key_secret) @instance_id = instance_id @key_id = key_id @key_secret = key_secret end |
Instance Method Details
#authenticate(auth_payload, options) ⇒ Object
16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 |
# File 'lib/pusher-platform/authenticator.rb', line 16 def authenticate(auth_payload, ) grant_type = auth_payload['grant_type'] || auth_payload[:grant_type] unless grant_type == "client_credentials" return AuthenticationResponse.new({ status: 422, body: { error: 'token_provider/invalid_grant_type', error_description: "The grant_type provided, #{grant_type}, is unsupported" } }) end authenticate_using_client_credentials() end |
#authenticate_with_refresh_token(auth_payload, options) ⇒ Object
37 38 39 |
# File 'lib/pusher-platform/authenticator.rb', line 37 def authenticate_with_refresh_token(auth_payload, ) authenticate_based_on_grant_type(auth_payload, ) end |
#authenticate_with_refresh_token_and_request(request, options) ⇒ Object
41 42 43 44 |
# File 'lib/pusher-platform/authenticator.rb', line 41 def authenticate_with_refresh_token_and_request(request, ) auth_data = Rack::Utils.parse_nested_query request.body.read authenticate_based_on_grant_type(auth_data, ) end |
#authenticate_with_request(request, options) ⇒ Object
32 33 34 35 |
# File 'lib/pusher-platform/authenticator.rb', line 32 def authenticate_with_request(request, ) auth_data = Rack::Utils.parse_nested_query request.body.read authenticate(auth_data, ) end |
#generate_access_token(options) ⇒ Object
46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 |
# File 'lib/pusher-platform/authenticator.rb', line 46 def generate_access_token() now = Time.now.utc.to_i claims = { instance: @instance_id, iss: "api_keys/#{@key_id}", iat: now, exp: now + TOKEN_EXPIRY } claims.merge!({ sub: [:user_id] }) unless [:user_id].nil? claims.merge!({ su: true }) if [:su] claims.merge!([:service_claims]) if [:service_claims] { token: JWT.encode(claims, @key_secret, 'HS256'), expires_in: TOKEN_EXPIRY } end |