Working!!!!

This commit is contained in:
Ben Hardill
2016-11-05 17:04:18 +00:00
parent 8070376a94
commit bad9415ba6
4 changed files with 77 additions and 30 deletions

View File

@@ -6,6 +6,8 @@ var server = oauth2orize.createServer();
server.grant(oauth2orize.grant.code({
scopeSeparator: [ ' ', ',' ]
}, function(application, redirectURI, user, ares, done) {
//console.log("grant user: ", user);
var grant = new OAuth.GrantCode({
application: application,
user: user,
@@ -21,14 +23,24 @@ server.exchange(oauth2orize.exchange.code({
}, function(application, code, redirectURI, done) {
OAuth.GrantCode.findOne({ code: code }, function(error, grant) {
if (grant && grant.active && grant.application == application.id) {
//console.log("exchange user ", grant.user);
var token = new OAuth.AccessToken({
application: grant.application,
user: grant.user,
grant: grant,
scope: grant.scope
});
token.save(function(error) {
done(error, error ? null : token.token, null, error ? null : { token_type: 'standard' });
var refreshToken = new OAuth.RefreshToken({
user: grant.user,
application: grant.application
});
refreshToken.save(function(error){
done(error, error ? null : token.token, refreshToken.token, error ? null : { token_type: 'standard' });
});
});
} else {
done(error, false);
@@ -36,6 +48,7 @@ server.exchange(oauth2orize.exchange.code({
});
}));
server.serializeClient(function(application, done) {
done(null, application.id);
});