add refreshToken, cleanup scopestringify
This commit is contained in:
parent
cecda1c36b
commit
30d62f94e0
|
@ -144,10 +144,7 @@
|
|||
params.state = state;
|
||||
params.response_type = responseType;
|
||||
if (scope) {
|
||||
if (Array.isArray(scope)) {
|
||||
scope = scope.join(' ');
|
||||
}
|
||||
params.scope = scope;
|
||||
params.scope = core.stringifyscope(scope);
|
||||
}
|
||||
if (clientId) {
|
||||
// In OAuth3 client_id is optional for implicit grant
|
||||
|
@ -277,10 +274,66 @@
|
|||
}
|
||||
|
||||
if (scope) {
|
||||
if (Array.isArray(scope)) {
|
||||
scope = scope.join(' ');
|
||||
}
|
||||
params.scope = scope;
|
||||
params.scope = core.stringifyscope(scope);
|
||||
}
|
||||
|
||||
if ('GET' === args.method.toUpperCase()) {
|
||||
uri += '?' + core.querystringify(params);
|
||||
} else {
|
||||
body = params;
|
||||
}
|
||||
|
||||
return {
|
||||
url: uri
|
||||
, method: args.method
|
||||
, data: body
|
||||
};
|
||||
};
|
||||
|
||||
core.refreshToken = function (directive, opts) {
|
||||
// grant_type=refresh_token
|
||||
|
||||
// Example Refresh Token Request
|
||||
// (generally for 1st or 3rd party server-side, mobile, and desktop apps)
|
||||
//
|
||||
// POST https://example.com/api/oauth3/access_token
|
||||
// { "grant_type": "refresh_token", "client_id": "<<id>>", "scope": "<<scope>>"
|
||||
// , "username": "<<username>>", "password": "password" }
|
||||
//
|
||||
opts = opts || {};
|
||||
var type = 'access_token';
|
||||
var grantType = 'refresh_token';
|
||||
|
||||
var scope = opts.scope || directive.authn_scope;
|
||||
var clientId = opts.appId || opts.clientId;
|
||||
var clientSecret = opts.appSecret || opts.clientSecret;
|
||||
var args = directive[type];
|
||||
var params = {
|
||||
"grant_type": grantType
|
||||
, "refresh_token": opts.refreshToken
|
||||
, "response_type": 'token'
|
||||
//, "client_id": undefined
|
||||
//, "client_uri": undefined
|
||||
//, "scope": undefined
|
||||
//, "client_secret": undefined
|
||||
};
|
||||
var uri = args.url;
|
||||
var body;
|
||||
|
||||
if (opts.clientUri) {
|
||||
params.client_uri = opts.clientUri;
|
||||
}
|
||||
|
||||
if (clientId) {
|
||||
params.client_id = clientId;
|
||||
}
|
||||
|
||||
if (clientSecret) {
|
||||
params.client_secret = clientSecret;
|
||||
}
|
||||
|
||||
if (scope) {
|
||||
params.scope = core.stringifyscope(scope);
|
||||
}
|
||||
|
||||
if ('GET' === args.method.toUpperCase()) {
|
||||
|
|
Loading…
Reference in New Issue