TypeScript - @azure/msal-node - accessToken type on AuthenticationResults
See original GitHub issueLibrary
-
@azure/msal-node@1.x.x
Description
I am using the latest version of the @azure/msal-node
module. I have a small typescript lambda that is creating an accessToken
using the OAuth 2.0 Client Credentials Grant
flow.
High level, I import the module:
import * as msal from '@azure/msal-node';
Setup my config:
const config = {
auth: {
clientId: client_id,
authority,
clientSecret: client_secret,
},
system: {
loggerOptions: {
loggerCallback(loglevel: any, message: any, containsPii: any) {
core.info(`${loglevel}:${message}:${containsPii} `);
},
piiLoggingEnabled: false,
logLevel: msal.LogLevel.Verbose,
},
},
};
Create the App & set scopes:
const cca = new msal.ConfidentialClientApplication(config);
const clientCredentialRequest = {
scopes: ['api://xxxx/.default'],
};
I then attempt to deconstruct the accessToken from the request by doing:
try {
const { accessToken } = await cca.acquireTokenByClientCredential(clientCredentialRequest);
return accessToken;
} catch (error) {
log(error)
}
}
However, I am getting the error:
Property 'accessToken' does not exist on type 'AuthenticationResult | null'.
On this line:
const { accessToken } = await cca.acquireTokenByClientCredential(clientCredentialRequest);
I have tried finding the @azure/msal-node
types library but I can’t find one.
I have got this working in Vanilla JS, but must admit I am new to TypeScript a little, so this is likely not a bug but on me, where about am I going wrong here, if you don’t mind me asking?
Source
- Internal (Microsoft)
- Customer request
Issue Analytics
- State:
- Created 2 years ago
- Comments:6 (5 by maintainers)
Top Results From Across the Web
@azure/msal-node - npm
The web API validates the token, and calls Microsoft Graph on behalf of the user who authenticated in the web application.
Read more >Tutorial: Sign in users in a Node.js & Express web app
The web app you build uses the Microsoft Authentication Library (MSAL) for Node. Follow the steps in this tutorial to: Register the application ......
Read more >Single-page application: Acquire a token to call an API
The pattern for acquiring tokens for APIs with MSAL.js is to first attempt a silent token request by using the acquireTokenSilent method. When ......
Read more >AuthorizationUrlRequest type alias - Microsoft Learn
Request object passed by user to retrieve a Code from the server (first leg of authorization code grant flow) scopes - Array of...
Read more >@azure/msal-node package | Microsoft Learn
This class is to be used to acquire tokens for public client applications (desktop, mobile). Public client applications are not trusted to safely...
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
@NickLiffen Closing this issue. We will follow up on strict null checks enhancement, I just do not have a clear timeline at this point. Marked it internally.
We added
strict null checks
in our code and hence had to support| null
in cases where it applied. I do think that some of the changes can be refined and possibly remove this for certain return types, but this would need changes in a lot of code. We will take it up eventually and I will mark this as an enhancement in our backlog.Hopefully we will get to it sooner than later 😃