We are using Angular 12 as Front End application & Web API (Asp.net Core 3.1). We have registered both the application in Azure AD & we are able to successfully fetch token from Azure AD.
Needed help on following:-
Can someone please guide me on steps for implementing it & also will it be implement on Front End or at Web API level?
Thanks a lot in advance
As you are almost there, To achieve the above requirement we can use below sample code to retrieve a user's profile with an HTTP request.
CODE:-
import { Component, OnInit } from '@angular/core';
import { HttpClient } from '@angular/common/http';
const GRAPH_ENDPOINT = 'Enter_the_Graph_Endpoint_Here/v1.0/me';
type ProfileType = {
givenName?: string,
surname?: string,
userPrincipalName?: string,
id?: string
};
@Component({
selector: 'app-profile',
templateUrl: './profile.component.html',
styleUrls: ['./profile.component.css']
})
export class ProfileComponent implements OnInit {
profile!: ProfileType;
constructor(
private http: HttpClient
) { }
ngOnInit() {
this.getProfile();
}
getProfile() {
this.http.get(GRAPH_ENDPOINT)
.subscribe(profile => {
this.profile = profile;
});
}
}
For complete setup please refer this MICROSOFT DOCUMENTATION| Acquire a token in Angular
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.