Skip to content

Instantly share code, notes, and snippets.

@ValterAndrei
Created April 9, 2025 12:14
Show Gist options
  • Save ValterAndrei/bff7d72f09d98e1b34004b8462a5d54a to your computer and use it in GitHub Desktop.
Save ValterAndrei/bff7d72f09d98e1b34004b8462a5d54a to your computer and use it in GitHub Desktop.
Google OAuth2 Testing Guide

Google OAuth2 Testing Guide

1. Gerar URL de redirecionamento e abrir no navegador

https://accounts.google.com/o/oauth2/auth?client_id=SEU_CLIENT_ID&redirect_uri=http://localhost:3000/users/auth/google_oauth2/callback&scope=profile%20email&response_type=code&access_type=offline

2. Copiar o código de autorização, após o login

http://localhost:3000/users/auth/google_oauth2/callback?code=SEU_CODIGO&scope=email+profile+openid+https%3A%2F%2Fwww.googleapis.com%2Fauth%2Fuserinfo.profile+https%3A%2F%2Fwww.googleapis.com%2Fauth%2Fuserinfo.email&authuser=1&prompt=consent

3. Gerar o token de acesso

curl -d "client_id=SEU_CLIENT_ID" \
     -d "client_secret=SEU_SECRET" \
     -d "code=SEU_CODIGO" \
     -d "grant_type=authorization_code" \
     -d "redirect_uri=http://localhost:3000/users/auth/google_oauth2/callback" \
     https://oauth2.googleapis.com/token

4. Validar o token de acesso

curl -H "Authorization: Bearer SEU_ACCESS_TOKEN" \
     https://www.googleapis.com/oauth2/v3/userinfo

5. Gerar outro token através do "refresh token"

curl -d "client_id=SEU_CLIENT_ID" \
     -d "client_secret=SEU_SECRET" \
     -d "refresh_token=SEU_REFRESH_TOKEN" \
     -d "grant_type=refresh_token" \
     https://oauth2.googleapis.com/token

6. Revogar acesso ao token

curl -d "token=SEU_TOKEN" \
     https://oauth2.googleapis.com/revoke

Referência: https://avohq.io/blog/social-login-rails-google-github

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment