0

How do I generate a bearer token for my personal identity, like the Microsoft web page does here when you click Try it and log in with your personal credentials?

For example, I would like to generate the bearer token programmatically in a pre-request script in Postman.

UPDATE: The below error happens in Postman if you don't remove "Bearer " from the token. See @BrunoLucasAzure answer.

Also, I have tried to copy the bearer token manually from the Microsoft "Try It" page into Postman as suggested by this answer and I get a 401:

{
    "error": {
        "code": "InvalidAuthenticationToken",
        "message": "The access token is invalid."
    }
}

Before you say it, I realize that I would want a Service Principal for productionalized usage, but I shouldn't need one to explore the APIs via my own tool (e.g. Postman).

successhawk
  • 3,071
  • 3
  • 28
  • 44

1 Answers1

1

How did you set your postman? if you login into the "try" you should get this: enter image description here

copy #1 and #2 like this. Dont copy the word bearer, only the token and under authorization select bearer token

enter image description here

  • Thank you. I must have had user error yesterday, because I thought I tried with and without "Bearer " prefix in the Token field. I gave this an upvote because I am sure it will be helpful to someone, however I am still looking for a way to automate this step. – successhawk Nov 15 '22 at 14:59