Comments (4)
I suppose you need to use scopes
to specify an API of interest. By default vuew-msal sets scopes: ["user.read"]
which requests access to MS Graph for reading user data from AD hence the audience value you see in returned token.
Actually I only worked with AD B2C so I can say about it. But I suppose it's very similar to regular AD regarding the process of acquiring access tokens. If your app and API share the same client ID (API serves solely as a backend for an app) then you can simply put this client ID to scopes:
auth: {
...
scopes: ['62...fa'] // your client ID
}
Otherwise, an API should have published scopes identified by URLs and an app should be granted some of these scopes in AD settings. Then you specify needed scope(s) in the scopes parameter.
auth: {
...
scopes: ['https://contoso.onmicrosoft.com/api/read'] // URL(s) of API scope(s) access to which is requested
}
Hope this helps.
from vue-msal.
This did the trick. I got a token with this call:
await msal.acquireToken({ scopes: ['https://myFunctionApp.azurewebsites.net/user_impersonation'] });
Thank you very much!
Now I'm in a weird spot where I want to be able to call MS Graph AND my API. But during the acquireToken method, it sets the msal object's accessToken to whatever is returned. I find that sometimes the calls' timing is weird and they won't be set as expected during the proper calls (e.g. an API call will happen after the Graph call and have the wrong token). Is there a way to store multiple tokens and use the appropriate one per request?
from vue-msal.
Sorry, cannot help you further :( As I see from the code, vue-msal only stores one "current" access token which is used for MS Graph calls. Probably, you'll be able to use several instances of vue-msal in the same app for working with different APIs/scopes.
from vue-msal.
No worries, I understand. I actually wound up implementing MSAL myself to have easier access to the MSAL methods. This project helped me understand it a lot better, though!
from vue-msal.
Related Issues (20)
- Support for MSAL.js 2.0? HOT 6
- Support for Vue3 HOT 6
- How can I use Azure AD B2C different policies with vue-msal? HOT 1
- Is there a small example?
- requireAuthOnInitialize not working and no docs on how to use with routes HOT 1
- null_or_empty_id_token errors on newer versions of msal HOT 5
- Accessing msal in vuex store HOT 2
- Nuxt mode requirement HOT 1
- the idToken property of both $msal.data and the mixin's data object are an empty string HOT 1
- Can access token null, because the scope can't read properly
- Donβt include src folder HOT 1
- Getting 401 request on graph call, something wrong with token HOT 3
- Support for MSAL 2.0 HOT 2
- msGraph - post|update requests HOT 2
- requireAuthOnInitialize: false doesn't work HOT 1
- AuthenticationFlow does not start
- Setting up without vue-msal HOT 7
- router
- Receiving error after changing app to https HOT 1
- AcquireToken don't return access token in Chrome, only work in Firefox and Edge
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
π Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. πππ
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google β€οΈ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from vue-msal.