Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Office365 login #345

Open
e404r opened this issue Jan 5, 2021 · 0 comments
Open

Office365 login #345

e404r opened this issue Jan 5, 2021 · 0 comments

Comments

@e404r
Copy link

e404r commented Jan 5, 2021

Thanks for the project 😍👍
But this project has no support office365 Login. I tried the options according to your code.

And the result:

  • [Getting an access token ] -Yes
  • [Get user Info] -Yes

`
$scope.office365Login = function() {

let client_id =  "APP_client_ID",
    client_secret = "APP_client_secret",
    tenant_id= "APP_tenant_ID",
    redirect_ur= "http://localhost/callback",
    scopes =  ["offline_access", "openid","https://outlook.office.com/mail.read"],
    accessUrl = "https://login.microsoftonline.com/common/oauth2/v2.0/authorize?client_id="+client_id+"&redirect_uri="+redirect_ur+"&response_type=code&scope="+scopes.join(" ",)+"",
    mapiM_url = "https://outlook.office.com/api/v2.0/Me";

    let browserRef = window.cordova.InAppBrowser.open(accessUrl, '_blank', 'location=no,clearsessioncache=yes,clearcache=yes');

    browserRef.addEventListener("loadstart", function(event) {

     if((event.url).indexOf('http://localhost/callback') === 0) {
        let requestToken = (event.url).split("code=")[1];
       setTimeout(function() { browserRef.close();  }, 10);

          $http({method: "post", headers: {'Content-Type': 'application/x-www-form-urlencoded'}, url: "https://login.microsoftonline.com/"+tenant_id+"/oauth2/v2.0/token", data:
                           "client_id=" + client_id +
                           "&code=" + requestToken +
                           "&client_secret="+  client_secret+
                           "&redirect_uri=http://localhost/callback&" +
                           "grant_type=authorization_code"}).success(function(data) {

             let access_token = data.access_token;

             $http({ method: 'GET',url:  mapiM_url, headers: {
                        "Authorization": "Bearer "+access_token,
                        "Accept": " text/*, multipart/mixed, application/xml, application/json; odata.metadata=none"
                       }

             }).then(function success(response) {

            // console.log(JSON.stringify(response.data))

             let Omymail =response.data.EmailAddress,
                 ODname =response.data.DisplayName;

             console.log("USER NAME: "+ODname+" AND "+"USER MAIL: "+Omymail)

             }, function error(response) {
             browserRef.close();
             console.log(JSON.stringify(response))
             });


         }).error(function(data, status) {
         browserRef.close();
         console.log(JSON.stringify(response))
         })


     }



        })


    }

`

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant