Apr 27, 2024 16:45 Parameters Returns Supported Clients Sample Parameters Returns Supported Clients SampleSupported Clients
NGClient
Methods Summary
OAuthService
getOAuthService(provider, clientId, clientSecret, scope, state, deeplinkmethod)
Creates an OAuth service that can be used to obtain an access token and access protected data.
OAuthServiceBuilder
serviceBuilder(clientID)
Creates an OAuth service configurator.
Methods Details
getOAuthService(provider, clientId, clientSecret, scope, state, deeplinkmethod)
Creates an OAuth service that can be used to obtain an access token and access protected data.
This method will be deprecated in the following versions, the preferred way is plugins.oauth.serviceBuilder with a callback function.
String
provider
an OAuth provider id, see plugins.oauth.OAuthProviders
String
clientId
your app id
String
clientSecret
your client secret
String
scope
configures the OAuth scope. This is only necessary in some APIs (like Microsoft's).
String
state
configures the anti forgery session state. This is available in some APIs (like Facebook's).
String
deeplinkmethod
the name of a global method, which will get the code returned by the OAuth provider
var clientId = "";
var clientSecret = "";
var scope = null;
var state = "secret123337";
var callback = "deeplink";
service = plugins.oauth.getOAuthService(plugins.oauth.OAuthProviders.FACEBOOK, clientId, clientSecret, null, state, callback, null)
application.showURL(service.getAuthorizationURL());
function deeplink(a,args) {
service.setAccessToken(args.code);
var response = service.executeGetRequest("https://graph.facebook.com/v2.11/me");
if (response.getCode() == 200) {
application.output(response.getBody());
var json = response.getAsJSON();
application.output("Name is "+json.name);
}
else {
application.output('ERROR http status '+response.getCode());
}
}
serviceBuilder(clientID)
Creates an OAuth service configurator.
String
clientID
;
plugins.oauth.serviceBuilder("0lqd1s0aw...") //client/application ID
.clientSecret("bIk6163KHi...") //client secret
.defaultScope("email") //ask permission to get the user email
.state("secret123337") //anti forgery session state, required by the Facebook api
.deeplink("deeplink_method") //OPTIONAL deeplink method name or last part of your redirect URL, see docs
//if missing, a global method with the name 'deeplink_svy_oauth' will be generated
.callback(myFunction, 30) //see function below, timeout is 30 seconds
.build(plugins.oauth.OAuthProviders.FACEBOOK);
function myFunction(result, auth_outcome) {
if (result)
{
//SUCCESS
var service = auth_outcome;
if (service.getAccessToken() == null) return;
var response = service.executeGetRequest("https://graph.facebook.com/v2.11/me");
if (response.getCode() == 200) {
application.output(response.getBody());
var json = response.getAsJSON();
application.output("Name is "+json.name);
}
else {
application.output('ERROR http status '+response.getCode());
}
else {
//ERROR
application.output("ERROR "+auth_outcome);//could not get access token, request timed out, etc..
}
}
}