Skip to content

Instantly share code, notes, and snippets.

View simonagren's full-sized avatar

Simon Ågren simonagren

View GitHub Profile
@simonagren
simonagren / file.ts
Created April 6, 2021 16:24
Quick example MSAL Node
/**
* Gets an access token for the user using the on-behalf-of flow
* @param authHeader - The Authorization header value containing a JWT bearer token
* @returns {Promise<string | null>} - Returns the access token if successful, null if not
*/
export async function getAccessTokenOnBehalfOf(req: Request, res: Response): Promise<void> {
// The token has already been validated, just grab it and the other values from the query string
const ssoToken: string = req.headers.authorization!.split(' ')[1];
const clientId: string = req.body.clientId!.toString();
const graphScopes: string[] = req.body.scopes!.toString().split(',');