react-oauth icon indicating copy to clipboard operation
react-oauth copied to clipboard

Get credentials with custom button

Open christophe13012 opened this issue 2 years ago • 1 comments

Hello, thanks for this package. Is it possible to get credientialResponse with custom buttons ? (and not tokenResponse) thanks for your help

christophe13012 avatar Oct 07 '22 14:10 christophe13012

Hey @christophe13012, did you figure it out?

tarunsoftprodigy avatar Oct 11 '22 13:10 tarunsoftprodigy

Hi!, you can but with authorization code flow, after exchanging the code with your backend you will get access, refresh, and id tokens

or if you are using it in implicit flow to get access token you can send request to google API to get user info

MomenSherif avatar Oct 17 '22 12:10 MomenSherif

Hi @MomenSherif Is there any direct way to get user credentials with custom button? Can you provide some examples for it?

raj2k00 avatar Oct 20 '22 05:10 raj2k00

Would love to see this

NisargIO avatar Oct 21 '22 05:10 NisargIO

You can get the user's credentials with this code.

const login = useGoogleLogin({
   onSuccess: async (res) => {
     const { data } = await axios(
       "https://www.googleapis.com/oauth2/v3/userinfo",
       {
         headers: {
           Authorization: `Bearer ${res?.access_token}`,
         },
       }
     );
     console.log(data);
   },
 });

sahilverma-dev avatar Oct 22 '22 08:10 sahilverma-dev

@theviralboy I am sorry for my silly question, where can I put your code to run :( I want to use Calendar API but I can not get refresh token, I can use default google button to login and I stuck, could you help me out of this , thank you so much

thang-39 avatar Oct 25 '22 14:10 thang-39

@theviralboy I am sorry for my silly question, where can I put your code to run :( I want to use Calendar API but I can not get refresh token, I can use default google button to login and I stuck, could you help me out of this , thank you so much

I think it's a separate issue. I am also not getting the refresh token.

sahilverma-dev avatar Oct 25 '22 14:10 sahilverma-dev

@theviralboy I am sorry for my silly question, where can I put your code to run :( I want to use Calendar API but I can not get refresh token, I can use default google button to login and I stuck, could you help me out of this , thank you so much

Try this https://www.npmjs.com/package/googleapis#oauth2-client

sahilverma-dev avatar Oct 25 '22 15:10 sahilverma-dev