Class: SignIn::AccessTokenJwtEncoder

Inherits:
Object
  • Object
show all
Defined in:
app/services/sign_in/access_token_jwt_encoder.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(access_token:) ⇒ AccessTokenJwtEncoder

Returns a new instance of AccessTokenJwtEncoder.



7
8
9
# File 'app/services/sign_in/access_token_jwt_encoder.rb', line 7

def initialize(access_token:)
  @access_token = access_token
end

Instance Attribute Details

#access_tokenObject (readonly)

Returns the value of attribute access_token.



5
6
7
# File 'app/services/sign_in/access_token_jwt_encoder.rb', line 5

def access_token
  @access_token
end

Instance Method Details

#jwt_encode_access_tokenObject (private)



37
38
39
# File 'app/services/sign_in/access_token_jwt_encoder.rb', line 37

def jwt_encode_access_token
  JWT.encode(payload, private_key, Constants::AccessToken::JWT_ENCODE_ALGORITHM)
end

#payloadObject (private)



17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
# File 'app/services/sign_in/access_token_jwt_encoder.rb', line 17

def payload
  {
    iss: Constants::AccessToken::ISSUER,
    aud: access_token.audience,
    client_id: access_token.client_id,
    jti: access_token.uuid,
    sub: access_token.user_uuid,
    exp: access_token.expiration_time.to_i,
    iat: access_token.created_time.to_i,
    session_handle: access_token.session_handle,
    refresh_token_hash: access_token.refresh_token_hash,
    device_secret_hash: access_token.device_secret_hash,
    parent_refresh_token_hash: access_token.parent_refresh_token_hash,
    anti_csrf_token: access_token.anti_csrf_token,
    last_regeneration_time: access_token.last_regeneration_time.to_i,
    version: access_token.version,
    user_attributes: access_token.user_attributes
  }
end

#performObject



11
12
13
# File 'app/services/sign_in/access_token_jwt_encoder.rb', line 11

def perform
  jwt_encode_access_token
end

#private_keyObject (private)



41
42
43
# File 'app/services/sign_in/access_token_jwt_encoder.rb', line 41

def private_key
  OpenSSL::PKey::RSA.new(File.read(Settings..jwt_encode_key))
end