Hello,
Does anyone already use the google Oauth 2.0 ?
I want to insert an event via api in google calendar but I need first to make a authentication request before inserting my event.
Unfortunately, I did not succeed to submit an authentication.
Any advise ?
Thx
pierre-yves
My fetch is:
const url = "https://accounts.google.com/o/oauth2/v2/auth";
const request = {
"redirect_uri": "https://www.think4jet.com/test-html",
"response_type": "=code&",
"client_id": "MY_CLIENT_ID",
"scope": "https://www.googleapis.com/auth/calendar"
};
return fetch(url, request);
.then(response => console.info(response.json()));
did it work? Can we see the code you used?
I am not sure. Look into https://developers.google.com/identity/protocols/OAuth2UserAgent for more information. I based my sample on that article.
Hi shay,
Thanks for your help!
I am losing my head on that particular issue, spending days without real progress ;(
I’ve got 2 questions regarding your proposal:
1- Do you think the https://accounts.google.com/o/oauth2/v2/auth? Is the correct one ?
I am thinking it should be an api address ? like https://www.googleapis.com ?
I did not find in the doc if it is correct
2 – Do you know how the redirect_uri parameter is working ?
I tried with yours but I’ve got the error: Error: redirect_uri_mismatch
In the google api console, I removed “Authorized redirect URIs”. Not sure this is the correct choice…
Thanks
Pierre-yves
Hi,
Instead of using fetch() use wixLocation.to.
Construct the URL to google authentication servers using the variables you mentioned above and then redirect the site to Google for authentication using wixLocation.to
The URL should be something like:
https://accounts.google.com/o/oauth2/v2/auth? scope=https%3A%2F%2Fwww.googleapis.com%2Fauth%2Fdrive.metadata.readonly& include_granted_scopes=true& state=state_parameter_passthrough_value& redirect_uri=http%3A%2F%2Foauth2.example.com%2Fcallback& response_type=token& client_id=client_id //Taken from Google docs at https://developers.google.com/identity/protocols/OAuth2UserAgent
Next, you'd need to use wixLocation.url to get the token from the page Google redirects the site.