MrSwitch / hello.js

A Javascript RESTFUL API library for connecting with OAuth2 services, such as Google+ API, Facebook Graph and Windows Live Connect
https://adodson.com/hello.js/
MIT License
4.63k stars 547 forks source link

Windows Live is depreciated, migrate to Microsoft Graph #588

Open JadedBlueEyes opened 5 years ago

JadedBlueEyes commented 5 years ago

Move to Azure AD v2, see MSAL js for reference implimentation in Typescript.

JadedBlueEyes commented 5 years ago

https://aka.ms/livesdkmigration

ratheeshkannan commented 5 years ago

We recently getting some errors due to this migration. Please upgrade. If anyone successfully migrated existing codebase to graph api. Please let us know.

dluc commented 5 years ago

I'm on day 3 trying to make hellojs (1.16 and 1.18) work with MS Graph and Typescript. Very frustrating, seeing plenty of errors, e.g.:

When basename is not configured:

TypeError: cannot use 'in' operator to search for 'paging' in '<!DOCTYPE html> ...' hello.all.js:2011 getPath hello.all.js:2011 onload hello.all.js:2277

When basename is configured:

Cross-Origin Request Blocked: The Same Origin Policy disallows reading the remote resource at https://www.graph.microsoft.com/v1.0/me?access_token=...

here's the config I'm testing, after checking various examples online:

hello.init(
    {
        msgraph: Config.appId
    },
    {
        display: "page",
        redirect_uri: Config.redirectUri,
        scope: Config.scope
    });

hello.init({
    msgraph: {
        name: "Microsoft Graph",
        oauth: {
            version: 2,
            auth: "https://login.microsoftonline.com/common/oauth2/v2.0/authorize",
        },
        scope_delim: " ",
        form: false,
        //base: "https://www.graph.microsoft.com/v1.0/",
    }
});
Ghryphen commented 5 years ago

New to hello.js, been looking into this as well trying to get MS Graph working.

@dluc One issue, I don't think the address should have www on the domain.

simplecommerce commented 1 year ago

Did any of you manage to migrate?

Update: ok so I got it working by creating my own instead of trying to extend the windows one.

I had to do something like this to get the basic working:

microsoft: {
            oauth: {
                version: 2,
                auth: "https://login.microsoftonline.com/common/oauth2/v2.0/authorize",
                grant: "https://login.microsoftonline.com/common/oauth2/v2.0/token",
            },
            // Authorization scopes
            scope: {
                basic: "User.Read", // this works but openid doesn't nor the information shown in the migrate page in previous post
                email: "Mail.Read",
                //birthday: 'wl.birthday',
                events: "Calendars.Read",
                // photos: 'Files.Read',
                // videos: 'wl.photos',
                // friends: 'wl.contacts_emails',
                files: "Files.Read",
                //publish: 'wl.share',
                //publish_files: 'wl.skydrive_update',
                //share: 'wl.share',
                create_event: "Calendars.ReadWrite,Calendars.ReadWrite",
                offline_access: "offline_access",
            },
            base: "https://graph.microsoft.com/v1.0/",
            scope_delim: " ",
            /**
             *
             * @param p
             */
            xhr: function (p) {
                p.headers = {
                    "Content-Type": "application/json",
                    "Authorization": `Bearer ${get(p, "authResponse.access_token")}`,  // this is required for their authentication (i am using lodash here)
                };

                return true;
            },
            wrap: {
                /**
                 *
                 * @param o
                 * @param headers
                 * @param req
                 */
                me: (o, headers, req) => {
                    if (o.id) {
                        o.last_name = o.surname || null;
                        o.first_name = o.givenName || null;
                        o.email = o.userPrincipalName; // i am trying to find out why o.mail is null at the moment
                    }

                    return o;
                },
            },
        },

I leave this as a example here in case anyone has the same issues or want to implement something for this.