Skip to content

Commit

Permalink
Add GitHub OAuth App to example (#193)
Browse files Browse the repository at this point in the history
  • Loading branch information
int128 authored Jun 15, 2024
1 parent c2106d9 commit e039b18
Showing 1 changed file with 35 additions and 5 deletions.
40 changes: 35 additions & 5 deletions example/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
```

Expand All @@ -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.

0 comments on commit e039b18

Please sign in to comment.