Class: Fb::Jwt::Auth::ServiceAccessToken

Inherits:
Object
  • Object
show all
Defined in:
lib/fb/jwt/auth/service_access_token.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(subject: nil, issuer: nil) ⇒ ServiceAccessToken

Returns a new instance of ServiceAccessToken.



10
11
12
13
14
15
# File 'lib/fb/jwt/auth/service_access_token.rb', line 10

def initialize(subject: nil, issuer: nil)
  @subject = subject
  @encoded_private_key = Fb::Jwt::Auth.encoded_private_key
  @namespace = Fb::Jwt::Auth.namespace
  @issuer = issuer || Fb::Jwt::Auth.issuer
end

Instance Attribute Details

#encoded_private_keyObject (readonly)

Returns the value of attribute encoded_private_key.



5
6
7
# File 'lib/fb/jwt/auth/service_access_token.rb', line 5

def encoded_private_key
  @encoded_private_key
end

#issuerObject (readonly)

Returns the value of attribute issuer.



5
6
7
# File 'lib/fb/jwt/auth/service_access_token.rb', line 5

def issuer
  @issuer
end

#namespaceObject (readonly)

Returns the value of attribute namespace.



5
6
7
# File 'lib/fb/jwt/auth/service_access_token.rb', line 5

def namespace
  @namespace
end

#subjectObject (readonly)

Returns the value of attribute subject.



5
6
7
# File 'lib/fb/jwt/auth/service_access_token.rb', line 5

def subject
  @subject
end

Instance Method Details

#generateObject



17
18
19
20
21
22
23
24
25
26
27
# File 'lib/fb/jwt/auth/service_access_token.rb', line 17

def generate
  return '' if encoded_private_key.blank?

  private_key = OpenSSL::PKey::RSA.new(encoded_private_key.chomp)

  JWT.encode(
    token,
    private_key,
    'RS256'
  )
end