From e039b188cd2e57fcf6fe1361648675951b5596be Mon Sep 17 00:00:00 2001 From: Hidetake Iwata Date: Sat, 15 Jun 2024 10:48:10 +0900 Subject: [PATCH] Add GitHub OAuth App to example (#193) --- example/README.md | 40 +++++++++++++++++++++++++++++++++++----- 1 file changed, 35 insertions(+), 5 deletions(-) diff --git a/example/README.md b/example/README.md index 9611421..839edd7 100644 --- a/example/README.md +++ b/example/README.md @@ -2,20 +2,28 @@ This is an example application using oauth2cli. +To build this application, -## Getting Started +```sh +go build +``` -Setup your Google API access: +## Google + +Create your OAuth client. 1. Open https://console.cloud.google.com/apis/credentials 1. Create an OAuth client ID where the application type is other. -Build and run the application: +Run this application. +```sh +./example -client-id xxx.apps.googleusercontent.com -client-secret xxxxxxxx ``` -% go build -% ./example -client-id xxx.apps.googleusercontent.com -client-secret xxxxxxxx + +```console 2019/10/03 00:01:35 Open http://localhost:53753 +... 2019/10/03 00:01:40 You got a valid token until 2019-10-03 01:01:40.083238 +0900 JST m=+3604.526750517 ``` @@ -29,3 +37,25 @@ You can set a certificate and key for the local server. ./example -client-id xxx.apps.googleusercontent.com -client-secret xxxxxxxx \ -local-server-cert ../e2e_test/testdata/cert.pem -local-server-key ../e2e_test/testdata/cert-key.pem ``` + +## GitHub + +Create your OAuth App. +Set the callback URL to `http://localhost`. + +Run this application. + +```sh +./example -auth-url https://github.com/login/oauth/authorize -token-url https://github.com/login/oauth/access_token -client-id xxxxxxxx -client-secret xxxxxxxx +``` + +```console +09:52:45.384489 main.go:84: Open http://localhost:61865 +09:52:45.384507 server.go:36: oauth2cli: starting a server at 127.0.0.1:61865 +09:52:45.491072 server.go:135: oauth2cli: sending redirect to https://github.com/login/oauth/authorize?client_id=... +``` + +You can set `-scopes` flag to request the scopes. +See https://docs.github.com/en/apps/oauth-apps/building-oauth-apps/scopes-for-oauth-apps. + +It will automatically open the browser and you can log in to GitHub.