Class: IapAuthenticator::JWS

Inherits:
Object
  • Object
show all
Defined in:
lib/iap_authenticator/jws.rb

Constant Summary collapse

ALGORITHM =
'RS256'

Instance Method Summary collapse

Constructor Details

#initialize(private_key, refresh_time_seconds, iss, target_audience) ⇒ JWS

Returns a new instance of JWS.



5
6
7
8
9
10
11
# File 'lib/iap_authenticator/jws.rb', line 5

def initialize(private_key, refresh_time_seconds, iss, target_audience)
  @private_key = private_key
  @refresh_time_seconds = refresh_time_seconds
  @iss = iss
  @aud = IapAuthenticator::Token::TokenURI
  @target_audience = target_audience
end

Instance Method Details

#assertionObject



13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
# File 'lib/iap_authenticator/jws.rb', line 13

def assertion
  exp = Time.now.to_i + @refresh_time_seconds
  iat = Time.now.to_i
  payload = {
    iss: @iss,
    aud: @aud,
    exp: exp,
    iat: iat,
    target_audience: @target_audience
  }

  begin
    token = JWT.encode payload, @private_key, ALGORITHM
  rescue
    raise "Unable to create JWT"
  end
  return token
end