Class: SignIn::ServiceAccountAccessTokenJwtDecoder

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

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(service_account_access_token_jwt:) ⇒ ServiceAccountAccessTokenJwtDecoder

Returns a new instance of ServiceAccountAccessTokenJwtDecoder.



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

def initialize(service_account_access_token_jwt:)
  @service_account_access_token_jwt = 
end

Instance Attribute Details

#service_account_access_token_jwtObject (readonly)

Returns the value of attribute service_account_access_token_jwt.



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

def 
  @service_account_access_token_jwt
end

Instance Method Details

#decode_key_arrayObject (private)



47
48
49
# File 'app/services/sign_in/service_account_access_token_jwt_decoder.rb', line 47

def decode_key_array
  [public_key, public_key_old].compact
end

#jwt_decode_service_account_access_token(with_validation) ⇒ Object (private)



26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
# File 'app/services/sign_in/service_account_access_token_jwt_decoder.rb', line 26

def (with_validation)
  decoded_jwt = JWT.decode(
    ,
    decode_key_array,
    with_validation,
    {
      verify_expiration: with_validation,
      algorithm: Constants::ServiceAccountAccessToken::JWT_ENCODE_ALGORITHM
    }
  )&.first
  OpenStruct.new(decoded_jwt)
rescue JWT::VerificationError
  raise Errors::AccessTokenSignatureMismatchError.new(
    message: 'Service Account access token body does not match signature'
  )
rescue JWT::ExpiredSignature
  raise Errors::AccessTokenExpiredError.new message: 'Service Account access token has expired'
rescue JWT::DecodeError
  raise Errors::AccessTokenMalformedJWTError.new message: 'Service Account access token JWT is malformed'
end

#perform(with_validation: true) ⇒ Object



11
12
13
14
15
16
17
18
19
20
21
22
# File 'app/services/sign_in/service_account_access_token_jwt_decoder.rb', line 11

def perform(with_validation: true)
  decoded_token = (with_validation)
  ServiceAccountAccessToken.new(service_account_id: decoded_token.,
                                audience: decoded_token.aud,
                                scopes: decoded_token.scopes,
                                user_attributes: decoded_token.user_attributes,
                                user_identifier: decoded_token.sub,
                                uuid: decoded_token.jti,
                                version: decoded_token.version,
                                expiration_time: Time.zone.at(decoded_token.exp),
                                created_time: Time.zone.at(decoded_token.iat))
end

#public_keyObject (private)



51
52
53
# File 'app/services/sign_in/service_account_access_token_jwt_decoder.rb', line 51

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

#public_key_oldObject (private)



55
56
57
58
59
# File 'app/services/sign_in/service_account_access_token_jwt_decoder.rb', line 55

def public_key_old
  return unless Settings..jwt_old_encode_key

  OpenSSL::PKey::RSA.new(File.read(Settings..jwt_old_encode_key)).public_key
end