Class: SMARTAppLaunch::BackendServicesAuthorizationRequestBuilder

Inherits:
Object
  • Object
show all
Defined in:
lib/smart_app_launch/backend_services_authorization_request_builder.rb

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(encryption_method:, scope:, iss:, sub:, aud:, content_type: 'application/x-www-form-urlencoded', grant_type: 'client_credentials', client_assertion_type: 'urn:ietf:params:oauth:client-assertion-type:jwt-bearer', exp: 5.minutes.from_now, jti: SecureRandom.hex(32), kid: nil) ⇒ BackendServicesAuthorizationRequestBuilder

Returns a new instance of BackendServicesAuthorizationRequestBuilder.



13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
# File 'lib/smart_app_launch/backend_services_authorization_request_builder.rb', line 13

def initialize(
  encryption_method:,
  scope:,
  iss:,
  sub:,
  aud:,
  content_type: 'application/x-www-form-urlencoded',
  grant_type: 'client_credentials',
  client_assertion_type: 'urn:ietf:params:oauth:client-assertion-type:jwt-bearer',
  exp: 5.minutes.from_now,
  jti: SecureRandom.hex(32),
  kid: nil
)
  @encryption_method = encryption_method
  @scope = scope
  @iss = iss
  @sub = sub
  @aud = aud
  @content_type = content_type
  @grant_type = grant_type
  @client_assertion_type = client_assertion_type
  @exp = exp
  @jti = jti
  @kid = kid
end

Instance Attribute Details

#audObject (readonly)

Returns the value of attribute aud.



10
11
12
# File 'lib/smart_app_launch/backend_services_authorization_request_builder.rb', line 10

def aud
  @aud
end

#client_assertion_typeObject (readonly)

Returns the value of attribute client_assertion_type.



10
11
12
# File 'lib/smart_app_launch/backend_services_authorization_request_builder.rb', line 10

def client_assertion_type
  @client_assertion_type
end

#content_typeObject (readonly)

Returns the value of attribute content_type.



10
11
12
# File 'lib/smart_app_launch/backend_services_authorization_request_builder.rb', line 10

def content_type
  @content_type
end

#encryption_methodObject (readonly)

Returns the value of attribute encryption_method.



10
11
12
# File 'lib/smart_app_launch/backend_services_authorization_request_builder.rb', line 10

def encryption_method
  @encryption_method
end

#expObject (readonly)

Returns the value of attribute exp.



10
11
12
# File 'lib/smart_app_launch/backend_services_authorization_request_builder.rb', line 10

def exp
  @exp
end

#grant_typeObject (readonly)

Returns the value of attribute grant_type.



10
11
12
# File 'lib/smart_app_launch/backend_services_authorization_request_builder.rb', line 10

def grant_type
  @grant_type
end

#issObject (readonly)

Returns the value of attribute iss.



10
11
12
# File 'lib/smart_app_launch/backend_services_authorization_request_builder.rb', line 10

def iss
  @iss
end

#jtiObject (readonly)

Returns the value of attribute jti.



10
11
12
# File 'lib/smart_app_launch/backend_services_authorization_request_builder.rb', line 10

def jti
  @jti
end

#kidObject (readonly)

Returns the value of attribute kid.



10
11
12
# File 'lib/smart_app_launch/backend_services_authorization_request_builder.rb', line 10

def kid
  @kid
end

#scopeObject (readonly)

Returns the value of attribute scope.



10
11
12
# File 'lib/smart_app_launch/backend_services_authorization_request_builder.rb', line 10

def scope
  @scope
end

#subObject (readonly)

Returns the value of attribute sub.



10
11
12
# File 'lib/smart_app_launch/backend_services_authorization_request_builder.rb', line 10

def sub
  @sub
end

Class Method Details

.buildObject



6
7
8
# File 'lib/smart_app_launch/backend_services_authorization_request_builder.rb', line 6

def self.build(...)
  new(...).authorization_request
end

Instance Method Details

#authorization_requestObject



67
68
69
70
71
72
# File 'lib/smart_app_launch/backend_services_authorization_request_builder.rb', line 67

def authorization_request
  uri = Addressable::URI.new
  uri.query_values = authorization_request_query_values

  { body: uri.query, headers: authorization_request_headers }
end

#authorization_request_headersObject



39
40
41
42
43
44
# File 'lib/smart_app_launch/backend_services_authorization_request_builder.rb', line 39

def authorization_request_headers
  {
    content_type:,
    accept: 'application/json'
  }.compact
end

#authorization_request_query_valuesObject



46
47
48
49
50
51
52
53
# File 'lib/smart_app_launch/backend_services_authorization_request_builder.rb', line 46

def authorization_request_query_values
  {
    'scope' => scope,
    'grant_type' => grant_type,
    'client_assertion_type' => client_assertion_type,
    'client_assertion' => client_assertion.to_s
  }.compact
end

#client_assertionObject



55
56
57
58
59
60
61
62
63
64
65
# File 'lib/smart_app_launch/backend_services_authorization_request_builder.rb', line 55

def client_assertion
  @client_assertion ||= ClientAssertionBuilder.build(
      client_auth_encryption_method: encryption_method, 
      iss: iss,
      sub: sub,
      aud: aud,
      exp: exp.to_i,
      jti: jti,
      kid: kid
      )
end