6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
|
# File 'lib/iap_authenticator/token.rb', line 6
def self.generate_bearer_token( assertion )
uri = URI(TokenURI)
begin
res = Net::HTTP.post_form(uri, 'grant_type' => JWTBearerType, 'assertion' => assertion)
rescue => e
raise e
end
if res.code.to_i != 200
error_description = JSON.parse(res.body)["error_description"]
error = JSON.parse(res.body)["error"]
raise("Request failed with error: #{error} and description: #{error_description}")
end
response_jwt = JSON.parse(res.body)["id_token"]
return response_jwt
end
|