How can I fetch the Token as a string as I need to pass the Bearer token to authenticate & call a REST service?
The code sample you provided implements sign in feature , if you want to get an access token , you could use acquireToken(resource: string): Observable<string>;
function to acquire access token for resource . For example, after login, you could refer to the code below which clicks a button to acquire a token for the graph api, then you could use that token to make an api call :
import {Component} from '@angular/core';
import {AdalService} from 'ng2-adal/core';
@Component({
selector: 'home',
template: '<div protected><h1>This is the dashboard page.</h1><button (click)="logOut()">Logout</button><button (click)="callAPI()">callAPI</button></div>'
})
export class HomeComponent {
constructor(
private adalService: AdalService
) {
console.log('Entering home');
}
public logOut() {
this.adalService.logOut();
}
public callAPI() {
this.adalService.acquireToken("https://graph.microsoft.com").subscribe(p => {
console.log("Acquired token = " + p);
//then you could set Authorization Bearer header and call microsft graph api
}, (error => {
console.log(error);
}));
}
}
How do I list the claims
Do you want to get the user profile information ? If yes , you could get that from this.adalService.userInfo