Class: SignIn::TokenResponseGenerator

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

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(params:, cookies:) ⇒ TokenResponseGenerator

Returns a new instance of TokenResponseGenerator.



8
9
10
11
12
13
14
15
16
17
18
19
20
21
# File 'app/services/sign_in/token_response_generator.rb', line 8

def initialize(params:, cookies:)
  @grant_type = params[:grant_type]
  @code = params[:code]
  @code_verifier = params[:code_verifier]
  @client_assertion = params[:client_assertion]
  @client_assertion_type = params[:client_assertion_type]
  @assertion = params[:assertion]
  @subject_token = params[:subject_token]
  @subject_token_type = params[:subject_token_type]
  @actor_token = params[:actor_token]
  @actor_token_type = params[:actor_token_type]
  @client_id = params[:client_id]
  @cookies = cookies
end

Instance Attribute Details

#actor_tokenObject (readonly)

Returns the value of attribute actor_token.



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

def actor_token
  @actor_token
end

#actor_token_typeObject (readonly)

Returns the value of attribute actor_token_type.



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

def actor_token_type
  @actor_token_type
end

#assertionObject (readonly)

Returns the value of attribute assertion.



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

def assertion
  @assertion
end

#client_assertionObject (readonly)

Returns the value of attribute client_assertion.



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

def client_assertion
  @client_assertion
end

#client_assertion_typeObject (readonly)

Returns the value of attribute client_assertion_type.



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

def client_assertion_type
  @client_assertion_type
end

#client_idObject (readonly)

Returns the value of attribute client_id.



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

def client_id
  @client_id
end

#codeObject (readonly)

Returns the value of attribute code.



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

def code
  @code
end

#code_verifierObject (readonly)

Returns the value of attribute code_verifier.



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

def code_verifier
  @code_verifier
end

#cookiesObject (readonly)

Returns the value of attribute cookies.



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

def cookies
  @cookies
end

#grant_typeObject (readonly)

Returns the value of attribute grant_type.



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

def grant_type
  @grant_type
end

#subject_tokenObject (readonly)

Returns the value of attribute subject_token.



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

def subject_token
  @subject_token
end

#subject_token_typeObject (readonly)

Returns the value of attribute subject_token_type.



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

def subject_token_type
  @subject_token_type
end

Instance Method Details

#generate_client_tokensObject (private)



38
39
40
41
42
43
44
45
46
# File 'app/services/sign_in/token_response_generator.rb', line 38

def generate_client_tokens
  validated_credential = CodeValidator.new(code:, code_verifier:, client_assertion:,
                                           client_assertion_type:).perform
  session_container = SessionCreator.new(validated_credential:).perform

  .info('session created', session_container.access_token.to_s)

  TokenSerializer.new(session_container:, cookies:).perform
end

#generate_service_account_tokenObject (private)



48
49
50
51
52
53
54
55
# File 'app/services/sign_in/token_response_generator.rb', line 48

def 
   = AssertionValidator.new(assertion:).perform
  .info('generated service account token', .to_s)

  encoded_access_token = ServiceAccountAccessTokenJwtEncoder.new(service_account_access_token:).perform

  (access_token: encoded_access_token)
end

#generate_token_exchange_responseObject (private)



57
58
59
60
61
62
63
64
# File 'app/services/sign_in/token_response_generator.rb', line 57

def generate_token_exchange_response
  exchanged_container = TokenExchanger.new(subject_token:, subject_token_type:, actor_token:,
                                           actor_token_type:, client_id:).perform

  .info('token exchanged', exchanged_container.access_token.to_s)

  TokenSerializer.new(session_container: exchanged_container, cookies:).perform
end

#performObject



23
24
25
26
27
28
29
30
31
32
33
34
# File 'app/services/sign_in/token_response_generator.rb', line 23

def perform
  case grant_type
  when Constants::Auth::AUTH_CODE_GRANT
    generate_client_tokens
  when Constants::Auth::JWT_BEARER_GRANT
    
  when Constants::Auth::TOKEN_EXCHANGE_GRANT
    generate_token_exchange_response
  else
    raise Errors::MalformedParamsError.new(message: 'Grant type is not valid')
  end
end

#serialized_service_account_token(access_token:) ⇒ Object (private)



70
71
72
73
74
75
76
# File 'app/services/sign_in/token_response_generator.rb', line 70

def (access_token:)
  {
    data: {
      access_token:
    }
  }
end

#sign_in_loggerObject (private)



66
67
68
# File 'app/services/sign_in/token_response_generator.rb', line 66

def 
  @sign_in_logger ||= Logger.new(prefix: self.class)
end