mirror of
https://github.com/hardillb/node-red-alexa-home-skill-web.git
synced 2025-12-21 17:50:20 +01:00
Added some logging to file
This commit is contained in:
19
oauth.js
19
oauth.js
@@ -9,6 +9,8 @@ server.grant(oauth2orize.grant.code({
|
||||
//console.log("grant user: ", user);
|
||||
OAuth.GrantCode.findOne({application: application, user: user},function(error,grant){
|
||||
if (!error && grant) {
|
||||
//console.log("Grant, existing grant code found");
|
||||
//console.log("%j", grant);
|
||||
done(null,grant.code);
|
||||
} else if (!error) {
|
||||
var grant = new OAuth.GrantCode({
|
||||
@@ -39,21 +41,26 @@ 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, found grant code")
|
||||
OAuth.AccessToken.findOne({application:application, user: grant.user, active: true}, function(error,token){
|
||||
if (token) {
|
||||
//console.log("Active access token found");
|
||||
//console.log("%j", token);
|
||||
OAuth.RefreshToken.findOne({application:application, user: grant.user},function(error, refreshToken){
|
||||
if (refreshToken){
|
||||
var expires = Math.round((token.expires - (new Date().getTime()))/1000);
|
||||
done(null,token.token, refreshToken.token,{token_type: 'Bearer', expires_in: expires});
|
||||
console.log("sent expires_in: " + expires);
|
||||
//console.log("refresh token found, sent expires_in: " + expires);
|
||||
} else {
|
||||
// Shouldn't get here unless there is an error as there
|
||||
// should be a refresh token if there is an access token
|
||||
console.log("no refresh token found for existing access token");
|
||||
console.log("%j",error);
|
||||
done(error);
|
||||
}
|
||||
});
|
||||
} else if (!error) {
|
||||
console.log("exchange, no access token found");
|
||||
var token = new OAuth.AccessToken({
|
||||
application: grant.application,
|
||||
user: grant.user,
|
||||
@@ -66,27 +73,33 @@ server.exchange(oauth2orize.exchange.code({
|
||||
//delete old refreshToken or reuse?
|
||||
OAuth.RefreshToken.findOne({application:application, user: grant.user},function(error, refreshToken){
|
||||
if (refreshToken) {
|
||||
console.log("Should never get here, new accessToken with old refresh token");
|
||||
done(error, error ? null : token.token, refreshToken.token, error ? null : { token_type: 'Bearer', expires_in: expires, scope: token.scope});
|
||||
} else if (!error) {
|
||||
//console.log("creating new refresh token")
|
||||
var refreshToken = new OAuth.RefreshToken({
|
||||
user: grant.user,
|
||||
application: grant.application
|
||||
});
|
||||
|
||||
refreshToken.save(function(error){
|
||||
//console.log("sending new token access and refresh token");
|
||||
done(error, error ? null : token.token, refreshToken.token, error ? null : { token_type: 'Bearer', expires_in: expires, scope: token.scope });
|
||||
});
|
||||
} else {
|
||||
console.log("err1");
|
||||
done(error);
|
||||
}
|
||||
});
|
||||
});
|
||||
} else {
|
||||
console.log("err2");
|
||||
done(error);
|
||||
}
|
||||
});
|
||||
|
||||
} else {
|
||||
console.log("err3");
|
||||
done(error, false);
|
||||
}
|
||||
});
|
||||
@@ -95,7 +108,7 @@ server.exchange(oauth2orize.exchange.code({
|
||||
server.exchange(oauth2orize.exchange.refreshToken({
|
||||
userProperty: 'appl'
|
||||
}, function(application, token, scope, done){
|
||||
console.log("Yay!");
|
||||
//console.log("Yay!");
|
||||
OAuth.RefreshToken.findOne({token: token}, function(error, refresh){
|
||||
if (refresh && refresh.application == application.id) {
|
||||
OAuth.GrantCode.findOne({},function(error, grant){
|
||||
|
||||
Reference in New Issue
Block a user