Skip to content

Instantly share code, notes, and snippets.

@jackiect
Created July 7, 2020 03:57
Show Gist options
  • Save jackiect/5960de86110b3485bbb32af1a75385f7 to your computer and use it in GitHub Desktop.
Save jackiect/5960de86110b3485bbb32af1a75385f7 to your computer and use it in GitHub Desktop.
makefile google oauth2 requests
GOOGLE_AUTH_PAGE=https://accounts.google.com/o/oauth2/auth
# GOOGLE_AUTH_PAGE_V2=https://accounts.google.com/o/oauth2/v2/auth
GOOGLE_TOKEN_API=https://oauth2.googleapis.com/token
GOOGLE_TOKEN_INFO_API=https://oauth2.googleapis.com/tokeninfo
# GOOGLE_TOKEN_INFO_API_V3=https://www.googleapis.com/oauth2/v3/tokeninfo
GOOGLE_REVOKE_API=https://oauth2.googleapis.com/revoke
GOOGLE_USERINFO_API_V3=https://www.googleapis.com/oauth2/v3/userinfo
GOOGLE_USER_PROFILE_API=https://www.googleapis.com/auth/userinfo.profile
GOOGLE_USER_ME_API=https://www.googleapis.com/userinfo/v2/me
CLIENT_ID=2938xxxxxphsddd1tve0.apps.googleusercontent.com
CLIENT_SECRET=_xaxxxxxxob
REDIRECT_URI=http://gitlab.xxxxx.com/users/auth/google_oauth2/callback
SCOPE=email+profile
STATE-FEED:=$(shell /bin/bash -c "echo $$RANDOM")
RESTRICT_HOSTED_DOMAIN=prefixxxemail.com
gen-login-btn-url:
@echo "\nBASE URL:"
@echo "$(GOOGLE_AUTH_PAGE)?response_type=code&access_type=offline&client_id=$(CLIENT_ID)&redirect_uri=$(REDIRECT_URI)&scope=$(SCOPE)&state=$(STATE-FEED)"
@echo "\nFORCE CONFIRM ACCOUNT:"
@echo "$(GOOGLE_AUTH_PAGE)?response_type=code&access_type=offline&prompt=consent&client_id=$(CLIENT_ID)&redirect_uri=$(REDIRECT_URI)&scope=$(SCOPE)&state=$(STATE-FEED)"
@echo "\nRESTRICT HD URL:"
@echo "$(GOOGLE_AUTH_PAGE)?response_type=code&access_type=offline&prompt=consent&client_id=$(CLIENT_ID)&redirect_uri=$(REDIRECT_URI)&scope=$(SCOPE)&state=$(STATE-FEED)&hd=$(RESTRICT_HOSTED_DOMAIN)"
@echo "\nIMPLICIT FLOW:"
@echo "$(GOOGLE_AUTH_PAGE)?response_type=token+id_token&prompt=consent&client_id=$(CLIENT_ID)&redirect_uri=$(REDIRECT_URI)&scope=$(SCOPE)&state=$(STATE-FEED)&hd=$(RESTRICT_HOSTED_DOMAIN)"
code-2-token:
@curl -X POST $(GOOGLE_TOKEN_API) -d "grant_type=authorization_code&client_id=$(CLIENT_ID)&client_secret=$(CLIENT_SECRET)&redirect_uri=$(REDIRECT_URI)&code=${CODE}"
token-info:
@curl $(GOOGLE_TOKEN_INFO_API)?access_token=$(TOKEN)
id-token-info:
@curl $(GOOGLE_TOKEN_INFO_API)?id_token=$(ID_TOKEN)
refresh-token:
@curl -X POST $(GOOGLE_TOKEN_API) -d "grant_type=refresh_token&client_id=$(CLIENT_ID)&client_secret=$(CLIENT_SECRET)&refresh_token=$(REFRESH_TOKEN)"
revoke-token:
@curl -X POST $(GOOGLE_REVOKE_API)?token=$(TOKEN)
userinfo:
@echo "\nUSERINFO FROM V3"
@curl -H "Authorization: Bearer $(TOKEN)" $(GOOGLE_USERINFO_API_V3)
@echo "\nUSERINFO ME"
@curl -H "Authorization: Bearer $(TOKEN)" $(GOOGLE_USER_ME_API)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment