I am using react-google-login plugin for React which provides me a Google oAUth Sign-in / Log-in component for React.
This is my component:
const LogIn = ({ artist_id }) => {
const responseGoogle = (response) => {
let {accessToken} = response;
console.log(response);
};
return (
<GoogleLogin
clientId="***MY CLIENT ID ***"
buttonText="Connect with Google"
accessType="offline"
prompt='consent'
scope="https://www.googleapis.com/auth/yt-analytics.readonly"
onSuccess={responseGoogle}
onFailure={responseGoogle}
/>
);
};
By inserting accessType='offline' and prompt='consent' I expect GoogleLogin to return,together with the other values, a REFRESH_TOKEN but it does not.
I also tried to insert responseType='code' to GoogleLogin props, in this case I expect to get an AUTHORIZATION CODE that should be used to get an ACCESS_TOKEN and a REFRESH_TOKEN by making a POST call:
(taken from documentation provided by Google: https://developers.google.com/identity/protocols/oauth2/web-server#exchange-authorization-code)
POST /token HTTP/1.1
Host: oauth2.googleapis.com
Content-Type: application/x-www-form-urlencoded
code=4/P7q7W91a-oMsCeLvIaQm6bTrgtp7&
client_id=your_client_id&
client_secret=your_client_secret&
redirect_uri=https%3A//oauth2.example.com/code&
grant_type=authorization_code
So, after getting an AUTHORIZATION_CODE, I tried to make this post call but I always get the following error:
{
"error": "invalid_grant",
"error_description": "Bad Request"
}
The question is:
- Should I get REFRESH_TOKEN from GoogleLogin component ? Maybe I missed to enter some props...
- Should I get an AUTHORIZATION_CODE and then try to exchange it with REFRESH_TOKEN by issuing a POST call to https://www.googleapis.com/oauth2/v4/token ?