Reputation: 341
i am adding Microsoft Graph API to an app, and Get is not working. I am not even sure that it send a request. The URL i got was from Microsoft Graph Explorer.
I am able to get authenticated correctly via ADAL, and get a token back. Here is the code:
import {Http, Headers} from "@angular/http";
import {Injectable} from "@angular/core";
//import 'rxjs/add/operator/map'
//import 'rxjs/add/operator/catch'
import 'rxjs/Rx';
@Injectable()
export class EmailRESTService {
data: any;
token = localStorage.getItem("token");
constructor(private http: Http) {
this.data = null;
}
load() {
console.log('Inside EmailREST Promise: ');
this.http.get('https://graph.microsoft.com/v1.0/me', {
headers: new Headers ({"Authorization": "Bearer " + this.token})
}).subscribe(data => {
if(data.status == 200){
this.data = data.json();
}
if(data.status!= 200){
console.log('SOmething worng in Subscribe');
}
});
}
}
I am getting this output:
console.log('Inside EmailREST Promise: ');
but no output after that. I have tried many suggestions/codes from the net without success.
Is this a matter of using ADAL Auth on the wrong API endpoint (Azure Graph API vs Graph API)? i tried using this URL: https://graph.windows.net/me?api-version for Azure Graph API without success
Thanks in advance.
Upvotes: 0
Views: 470
Reputation: 341
Thank you everyone for your feedback. i appreciate it. I managed to get a token for Azure AD graph API and call that library. however, this gives me access to user/group operations, not email and other operations, which i need. I was just on the phone with Microsoft and they advised me to use MSAL, not ADAL. MSAL javascript package is under preview. And they have no cordova package out yet. Only native devices. I will see how that works for me. Even though i installed the package using npm in my project, and using their tutorial here: https://github.com/AzureAD/microsoft-authentication-library-for-js i am still getting some errors on real time of "can't find variable Msal", i believe this is not an Msal issue per se, but an import issue. And again, i can't strees this enough" Azure AD graph API" is not the same as "graph API", and the former will only give you access to user operations. So be careful and don't waste your time on it if you are looking to get email functionality
Upvotes: 1
Reputation: 14649
Based on the code, you were acquire the token for the Azure AD Graph. However, in the code, you were calling the Microsoft Graph(https://graph.microsoft.com/v1.0/me
) instead of Azure AD Graph.
To can the user info via Azure AD Graph, you can refer the rest below:
GET:https://graph.windows.net/myorganization/me?api-version=1.6
authorization: bearer {access_token}
Or you can call the Microsoft Graph via get the corresponding token as Dan Kershaw mentioned in the comment.
Upvotes: 0