8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
|
# File 'lib/floe/servicenow/oauth.rb', line 8
def self.token(params, secrets, context)
error = verify_instance_id(params)
return ServiceNow.error!({}, :cause => error) if error
instance_id = params["instance_id"]
= {
"ContentType" => "application/x-www-form-urlencoded",
"Accept" => "application/json"
}
body_params = {}
body_params["grant_type"] = params["grant_type"] if params["grant_type"]
body_params["client_id"] = params["client_id"] if params["client_id"]
body_params["scope"] = params["scope"] if params["scope"]
body_params["username"] = secrets["username"] if secrets["username"]
body_params["password"] = secrets["password"] if secrets["password"]
body_params["client_secret"] = secrets["client_secret"] if secrets["client_secret"]
body_params["refresh_token"] = secrets["refresh_token"] if secrets["refresh_token"]
http_params = {
"Method" => "POST",
"Headers" => ,
"Url" => "https://#{instance_id}.service-now.com/oauth_token.do",
"Body" => body_params
}
http_request(http_params, secrets, context)
end
|