I'm really struggling with connecting Salesforce and Microsoft Teams / Graph API.

Scenario: We want a customer support agent to be able to check an Event as "Microsoft Teams Meeting" and it should create the URL meeting as it's shown in this video: see Salesforce demo

I'm looking at the Graph API doc, and it says we need to make an OAuth with the 3 steps

  • Authorize
  • Get the token
  • Consume the resource

My problem is at the Authorize's point. I'm calling with an HTTP REST API to the /authorize endpoint, and I'm getting as a response an HTML page with the "Do you want to grant access...." thing, so I'm not getting directly the code I'm expecting.

Any charitable soul who can tell me how to surpass this?

Thanks in advance!!


OAuth's flow is meant to be an interactive experience with the login server. What you're meant to do is to redirect the user to the endpoint. Once the user clicks "Yes" to confirm access, an access code is sent back to the origin server to complete the final steps. That looks like this:

Salesforce          Microsoft
Redirect -------->  
                    Login (if not already)
Get Token <-------

Note that neither the Login nor Authorize steps occur on your end; the remote server does this.

Use the redirect_uri parameter to specify the page that gets the token back. As an example, let's say you're using Visualforce, then you'd have two pages: RedirectToLogin and GetAccessToken. The request would include a URL for "mydomain.my.salesforce.com/apex/GetAccessToken", and once successful, you could carry on with your business.

OAuth2 has a variety of ways you could implement in Salesforce, including just using a Named Credential in OAuth mode, but you can't directly login without some browser-side assistance. It's meant as a security feature.

  • Thanks a lot for your comment @sfdcfox. So, if I cannot avoid the /authorize to show me a webpage, could I have an approved code loaded directly in Salesforce to consume only the /token instead? That'd solve my issue, wouldn't it? – user3529582 Apr 21 at 11:42
  • @user3529582 Yes, you just need to redirect to the authorize page, and when it redirects back to Salesforce, you'll have a access code you can use to get the token. – sfdcfox Apr 21 at 11:50

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.