0

I am trying to get a token from a microsoft url. I have tried various different ways but it doesn't seem to work for me.

1

Below is the code I am writing in the HTTP trigger, I was trying to do a OAuth2 request.

{
    "inputs": {
        "method": "POST",
        "uri": "https://login.microsoftonline.com/c4fc2879-f0f4-45cd-8cb5-f17f4a078158/oauth2/token",
        "headers": {
            "Content_Type": "application/x-www-form-urlencoded"
        },
        "body": "grant_type=client_credentials&client_id=<>&client_secret=<>&resource=<>
    }
}

I have added in the client id and client secret, also the resource but it doesn't seem to work.

vimuth
  • 5,064
  • 33
  • 79
  • 116
M.Awais
  • 1
  • 2
  • Why are you explicitly trying to call the auth endpoint? You should instead probably investigate relying on a managed identity and giving permissions to that identity, or, if that's somehow not possible, use MSAL to interface with Azure AD instead of doing raw HTTP requests yourself. – julealgon Feb 16 '23 at 14:59
  • edited: I was trying to do a OAuth2 request – M.Awais Feb 16 '23 at 15:23
  • But the point is that you shouldn't need to do any of this manually. Azure has the concept of managed identities precisely to simplify this type of access. I'd strongly recommend reading into that a bit before proceeding with your solution. – julealgon Feb 16 '23 at 17:16

1 Answers1

0

I have reproduced issue from my side and below are steps i followed,

  • In Http action, calling authentication url with method type post.

  • Passing username, password and grant_type in body in json format. Kindly note that in your case, pass client id and client secret and the content type which your request will accept. In my case i have user name and password and expected content type is json. enter image description here

  • Next taken another HTTP action, which will used to get data by passing token obtained from previous action. enter image description here

  • Logic app able to get token from authentication url and able to get data using bearer toke. enter image description here enter image description here

Second Http action output: enter image description here

Refer the SO which is similar to your case and it may help you to solve issue.

vijaya
  • 1,525
  • 1
  • 2
  • 6