简体   繁体   中英

oauth2 for service account

I want to have a Google API Script deployed as a web app. I understand how to do that.

I want this script to list and add events on a Google Calendar. I have plenty of documentation and examples to do that.

I want this script to read a calendar using a service account. I have already created the service account and shared the calendar with it.

The end goal is to have a Javascript client access this script, use it to retrieve a list of events on the calendar and use it to create events on it.

What I don't understand is how to authenticate a service account. I keep seeing code like:

oauthConfig.setConsumerKey("anonymous"); oauthConfig.setConsumerSecret("anonymous"); oauthConfig.setRequestTokenUrl( " https://www.google.com/accounts/OAuthGetRequestToken?scope= "+scope); oauthConfig.setAuthorizationUrl(" https://accounts.google.com/OAuthAuthorizeToken "); oauthConfig.setAccessTokenUrl(" https://www.google.com/accounts/OAuthGetAccessToken ");

How do I modify this to use a service account? I do not understand if/how I pass in the service account client id/email address. I also am unclear how to pass in the public/private keys.

Can anyone help?

The Drive API documentation has a really good example on how to use service account. It has steps by steps on how to create a service account, and it also includes multiple code samples. The only thing is you would have to change the scope to Calendar API from Drive API.

https://developers.google.com/drive/web/delegation

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM