Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[FIX] Custom Oauth store refresh and id tokens with expiresIn #14121

Merged
merged 7 commits into from
Apr 16, 2019
19 changes: 14 additions & 5 deletions app/custom-oauth/server/custom_oauth_server.js
Original file line number Diff line number Diff line change
Expand Up @@ -130,7 +130,7 @@ export class CustomOAuth {
if (data.error) { // if the http response was a json object with an error attribute
throw new Error(`Failed to complete OAuth handshake with ${ this.name } at ${ this.tokenPath }. ${ data.error }`);
} else {
return data.access_token;
return data;
}
}

Expand Down Expand Up @@ -172,10 +172,10 @@ export class CustomOAuth {
registerService() {
const self = this;
OAuth.registerService(this.name, 2, null, (query) => {
const accessToken = self.getAccessToken(query);
// console.log 'at:', accessToken
const response = self.getAccessToken(query);
// console.log('app/custom-oauth/server/custom_oauth_server.js: self.getAccessToken()=', response);

let identity = self.getIdentity(accessToken);
let identity = self.getIdentity(response.access_token);

if (identity) {
// Set 'id' to '_id' for any sources that provide it
Expand Down Expand Up @@ -254,9 +254,18 @@ export class CustomOAuth {

const serviceData = {
_OAuthCustom: true,
accessToken,
accessToken: response.access_token,
idToken: response.id_token,
expiresAt: (+new Date) + (1000 * parseInt(response.expires_in, 10)),
geekgonecrazy marked this conversation as resolved.
Show resolved Hide resolved
};

// only set the token in serviceData if it's there. this ensures
// that we don't lose old ones (since we only get this on the first
// log in attempt)
if (response.refresh_token) {
serviceData.refreshToken = response.refresh_token;
}

_.extend(serviceData, identity);

const data = {
Expand Down