google / google-api-javascript-client

Google APIs Client Library for browser JavaScript, aka gapi.
Apache License 2.0
3.22k stars 1.06k forks source link

Need better examples for using with authentication #933

Open rmetcalf9 opened 1 year ago

rmetcalf9 commented 1 year ago

Important gapi.auth2 notice: gapi.auth2 has been deprecated and replaced with Google Identity Services. Please see https://developers.google.com/identity/sign-in/web/deprecation-and-sunset for more information. If you have questions related to authentication/authorization please look at the associated documentation or post questions on Stack Overflow with the google-oauth tag.

(I don't know what the above means on the issue template. Should this library be used for calling google api's in a webapp)

Summary I am working on a webapp which I want to use google login to call google API's while the user is present. I have followed instructions here - https://developers.google.com/identity/authentication I have generated a button and it is working and I can login and I get a response simular to the following in a javascript callback:

{clientId: 'xx', 
client_id: 'xx', 
credential: 'yyy', 
select_by: 'user'}

The credential is a valid JWT token and I have verified it at jwt.io. The problem is I now need to know how to use this credential to call an API. https://developers.google.com/identity/authorization says I should use a library to quickly and securly call google API's. The links bring me to this repo. I can see no reference to this credential anywhere in this repo. This repo talks about an access token which is different to the credential JWT token. I can't find how I should be exchanging one to the other.

Can a sample be added to this library which shows how it should be used?

Browser(s)/Version(s) All of them

Expected Behavior I should come to this repo and it should have at least one example of how to use the credential to call an API.

Actual Behavior I get lots of examples using an out dated method which won't work because new google client id's have this method disabled.

Steps to Reproduce Try and develop a webapp that uses google API's.

hermz365 commented 1 year ago

For authorization, you need access token. You can use Google Identity Services JavaScript for Web SDK to obtain access token. See https://developers.google.com/identity/oauth2/web/guides/overview.

There are more sample code under this page - https://developers.google.com/identity/oauth2/web/guides/migration-to-gis.