Comments (3)
@MonizDave thank you very much for catching this! I'll fix the link asap. About your issue, can you share your Angular SPA configuration file? (i.e.active-directory-javascript-singlepageapp-angular/src/app/app.module.ts/
).
To call this API, it should look like this:
@NgModule({
declarations: [
AppComponent,
ProfileComponent,
HomeComponent
],
imports: [
BrowserModule,
AppRoutingModule,
BrowserAnimationsModule,
HttpClientModule,
MatToolbarModule,
MatButtonModule,
MatListModule,
AppRoutingModule,
MsalModule.forRoot({
auth: {
clientId: 'SPA_CLIENT_ID',
authority: 'https://login.microsoftonline.com/YOUR_TENANT_ID',
redirectUri: 'http://localhost:4200',
},
cache: {
cacheLocation: 'localStorage',
storeAuthStateInCookie: isIE, // set to true for IE 11
},
},
{
popUp: !isIE,
consentScopes: [
'user.read',
'openid',
'profile',
'api://API_CLIENT_ID/access_as_user'
],
unprotectedResources: [],
protectedResourceMap: [
['http://localhost:5000/api', ['api://API_CLIENT_ID/access_as_user']]
],
extraQueryParameters: {}
})
],
providers: [
{
provide: HTTP_INTERCEPTORS,
useClass: MsalInterceptor,
multi: true
}
],
bootstrap: [AppComponent]
})
export class AppModule { }
Then, your active-directory-javascript-singlepageapp-angular/src/app/profile/profile.component.ts
file should be modified like this:
const API_ENDPOINT = 'https://graph.microsoft.com/v1.0/me';
@Component({
selector: 'app-profile',
templateUrl: './profile.component.html',
styleUrls: ['./profile.component.css']
})
export class ProfileComponent implements OnInit {
profile;
constructor(private authService: MsalService, private http: HttpClient) { }
ngOnInit() {
this.getProfile();
}
getProfile() {
this.http.get(API_ENDPOINT)
.subscribe({
next: (profile) => {
this.profile = profile;
},
error: (err: AuthError) => {
// If there is an interaction required error,
// call one of the interactive methods and then make the request again.
if (InteractionRequiredAuthError.isInteractionRequiredError(err.errorCode)) {
this.authService.acquireTokenPopup({
scopes: this.authService.getScopesForEndpoint(API_ENDPOINT)
})
.then(() => {
this.http.get(API_ENDPOINT)
.toPromise()
.then(profile => {
this.profile = profile;
});
});
}
}
});
}
}
from active-directory-javascript-nodejs-webapi-v2.
Thank you!
This level of detail should be added to the instructions.
from active-directory-javascript-nodejs-webapi-v2.
Will work on that, thanks @MonizDave
from active-directory-javascript-nodejs-webapi-v2.
Related Issues (12)
- Documentation HOT 2
- How to get reason of token validation failure? HOT 4
- req.user is undefined HOT 2
- Is it best practice to use sessions? HOT 4
- The client links in the overview are 404'd HOT 2
- Authentication failed due to: jwt audience is invalid HOT 3
- dead link?
- UPN, Profile ID missing from Account info page HOT 2
- Documentation HOT 1
- Authentication failed due to: In Strategy.prototype.jwtVerify: cannot verify token HOT 2
- cannot get AAD Federation metadata from endpoint you specified HOT 13
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 active-directory-javascript-nodejs-webapi-v2.