user10231828
user10231828

Reputation: 21

Does Google OAuth2.0 support grant_type=password?

This is my command

curl https://accounts.google.com/o/oauth2/token -d "client_id=111111111111%2D8pc07m34pj5eb5nid0u5n9fgs5vrndpm%2Eapps%2Egoogleusercontent%2Ecom&grant_type=password&username=123456%2E123%40gmail%2Ecom&password=123456&scope=https%3A%2F%2Fwww%2Egoogleapis%2Ecom%2Fauth%2Fcalendar&redirect_url=https%3A%2F%2Fwww%2Egoogle%2Ecom"

but I keep getting:

{
  "error" : "invalid_request"
}

I am trying to write an app which can read calendar data of any gmail account specified in the command line:

./foo [email protected] password

But I don't know how my foo can use gmailID and password to get a token w/o user interaction (i.e., open the url and click "Accept") so I can use the token to call Google Calendar APIs to read calendar data of that gmail account. I am new to this. Am I at least on the right track?

Upvotes: 2

Views: 2208

Answers (1)

Ruben Lopez
Ruben Lopez

Reputation: 734

You cannot send mail and password on grant_type and you cannot do requests on behalf of users without their permission, they need to give their consent.

In case you want to do requests on behalf of users (when they are not present in your application) you need to implement offline access. I suggest you to take a look on this reference.

Once users accept permissions to use your application, Google will generate a refreshToken that you need to store in your database. With that refreshToken you will be able to generate new access tokens and you will use these tokens to do your requests.

Upvotes: 3

Related Questions