Handle token difference in Microsoft provider
Signed-off-by: Adi Krhan <adikrhan43@gmail.com>
This commit is contained in:
@@ -0,0 +1,5 @@
|
||||
---
|
||||
'@backstage/plugin-auth-backend': patch
|
||||
---
|
||||
|
||||
Handle difference in expiration time between Microsoft session and Backstage session which caused the Backstage token to be invalid during a time frame.
|
||||
@@ -50,6 +50,8 @@ import {
|
||||
import { Logger } from 'winston';
|
||||
import fetch from 'node-fetch';
|
||||
|
||||
const BACKSTAGE_SESSION_EXPIRATION = 3600;
|
||||
|
||||
type PrivateInfo = {
|
||||
refreshToken: string;
|
||||
};
|
||||
@@ -145,12 +147,17 @@ export class MicrosoftAuthProvider implements OAuthHandlers {
|
||||
|
||||
const { profile } = await this.authHandler(result, this.resolverContext);
|
||||
|
||||
const expiresInSeconds =
|
||||
result.params.expires_in === undefined
|
||||
? BACKSTAGE_SESSION_EXPIRATION
|
||||
: Math.min(result.params.expires_in, BACKSTAGE_SESSION_EXPIRATION);
|
||||
|
||||
const response: OAuthResponse = {
|
||||
providerInfo: {
|
||||
idToken: result.params.id_token,
|
||||
accessToken: result.accessToken,
|
||||
scope: result.params.scope,
|
||||
expiresInSeconds: result.params.expires_in,
|
||||
expiresInSeconds,
|
||||
},
|
||||
profile,
|
||||
};
|
||||
|
||||
Reference in New Issue
Block a user