none
Getting data from graph using adal-angular RRS feed

  • Question

  • I'm using adal-angular to create an Office add in, that runs inside the office clients. I've created the project by using the Yeoman Office generator, and made a task-pane project.

    After entering all configurations, and the project finished building, I ran the project. As expected the user was prompted to log in. After logging in, I was redirected to my home page.

    This all seems very simple, but there are no API request in this start up project whatsoever, making it somewhat a useless template, except for the adal injection here and there.

    I expected to get data from graph by having these configurations:

    function adalConfigurator($httpProvider, adalProvider, appId){
        var adalConfig = {
            tenant: 'common',
            clientId: appId,
            extraQueryParameter: 'nux=1', //Default, I didn't enter this myself
            endpoints = {
               'https://graph.microsoft.com': 'https://graph.microsoft.com'
            },
            cacheLocation: 'localStorage'
        };
        adalProvider.init(adalConfig, $httpProvider);
    }

    Notice: I haven't touched the following properties: tenant, clientId, extraQueryparameter, endpoints. This all comes out of the box. Seeing this, I would expect that the token received from the login in the beginning of the app load, is an access token to the Graph API.

    Expecting such, I've made a function in my service, to get the current user from graph using this route: 'https://graph.microsoft.com/v1.0/me'.

    Here's said function:

    function getMe () {
        var deferred = $q.defer();
        $http.get('https://graph.microsoft.com/v1.0/me')
            .then(function success (response) {
                console.log('Success!');
                return deferred.resolve(response);
            }, function errorCallback (response) {
                console.log('Error!');
                deferred.reject(response);
            });
        return deferred.promise;
    }

    Again, as the token I get is towards the Graph API, I expect that I would be able to call the Graph API with no problems. I've read some documentation explaining that the Authorization header is applied automatically, if the token can be found in he cache. As I've defined the cache location to be localStorage, I've checked to see if the token is actually there which is it.

    When I actually make the request though, I've experienced several scenarios. 1) an infinite loop with the refresh token, 2) missing consent which requires additional action?, 3) no response comes back, 4) error from Office.js because the redirect reloads the entire app.

    I've experienced these 4 scenarios by tweeking the configurations and the actual $http.get all, but they all have one thing in common: none of them actually works.

    It would be neat to see some documentation on this, as it seems like a simple task. Two Microsoft technologies talking together, should be an easy task, but authorization is never easy, and the documentation in buried deep somewhere no one will ever find.

    I suppose I should be able to connect to the Graph API using adal-angular in an Office add in. Ultimately I'd like to connect to a SharePoint site. Is this even possible? And if so, how?

    EDIT: 

    My app settings in Azure AD are this:

    Sign-on url: https://localhost:8843

    Reply url: https://localhost:8843

    Permissions:

    • Microsoft Graph: Delegated Permission: 'Sign in and read user profile'

    With the configurations you see above, I'm getting this error:

    SCRIPT5022: Office.js has not been fully loaded yet. Please try again later or make sure to add your initialization code on the Office.initialize function.


    Tuesday, August 16, 2016 9:53 AM

All replies

  • Hi ChristianHaase,

    This is the forum to discuss questions and feedback for Developing Apps for Office 2013, I'll move your question to the MSDN forum for Office 365 for Developers

    https://social.msdn.microsoft.com/Forums/office/en-US/home?forum=Office365forDevelopers

    The reason why we recommend posting appropriately is you will get the most qualified pool of respondents, and other partners who read the forums regularly can either share their knowledge or learn from your interaction with us.

    Thanks for your understanding.
    Wednesday, August 17, 2016 9:56 AM
  • I'm having the same issue and theere is not much information.

    Could you tell me how you solved it?

    Tuesday, October 1, 2019 4:37 PM