forked from oauthjs/node-oauth2-server
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
bc7211b
commit c33a2cd
Showing
9 changed files
with
536 additions
and
283 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,87 @@ | ||
'use strict'; | ||
|
||
/** | ||
* Module dependencies. | ||
*/ | ||
|
||
var AbstractGrantType = require('./abstract-grant-type'); | ||
var InvalidArgumentError = require('../errors/invalid-argument-error'); | ||
var Promise = require('bluebird'); | ||
var util = require('util'); | ||
|
||
/** | ||
* Constructor. | ||
*/ | ||
|
||
function ImplicitGrantType(options) { | ||
options = options || {}; | ||
|
||
if (!options.model) { | ||
throw new InvalidArgumentError('Missing parameter: `model`'); | ||
} | ||
|
||
if (!options.model.saveToken) { | ||
throw new InvalidArgumentError('Invalid argument: model does not implement `saveToken()`'); | ||
} | ||
|
||
if (!options.user) { | ||
throw new InvalidArgumentError('Missing parameter: `user`'); | ||
} | ||
|
||
this.scope = options.scope; | ||
this.user = options.user; | ||
|
||
AbstractGrantType.call(this, options); | ||
} | ||
|
||
/** | ||
* Inherit prototype. | ||
*/ | ||
|
||
util.inherits(ImplicitGrantType, AbstractGrantType); | ||
|
||
/** | ||
* Handle implicit token grant. | ||
*/ | ||
|
||
ImplicitGrantType.prototype.handle = function(request, client) { | ||
if (!request) { | ||
throw new InvalidArgumentError('Missing parameter: `request`'); | ||
} | ||
|
||
if (!client) { | ||
throw new InvalidArgumentError('Missing parameter: `client`'); | ||
} | ||
|
||
return this.saveToken(this.user, client, this.scope); | ||
}; | ||
|
||
/** | ||
* Save token. | ||
*/ | ||
|
||
ImplicitGrantType.prototype.saveToken = function(user, client, scope) { | ||
var fns = [ | ||
this.validateScope(user, client, scope), | ||
this.generateAccessToken(), | ||
this.getAccessTokenExpiresAt() | ||
]; | ||
|
||
return Promise.all(fns) | ||
.bind(this) | ||
.spread(function(scope, accessToken, accessTokenExpiresAt) { | ||
var token = { | ||
accessToken: accessToken, | ||
accessTokenExpiresAt: accessTokenExpiresAt, | ||
scope: scope | ||
}; | ||
|
||
return this.model.saveToken(token, client, user); | ||
}); | ||
}; | ||
|
||
/** | ||
* Export constructor. | ||
*/ | ||
|
||
module.exports = ImplicitGrantType; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.