example

command
v1.15.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Jan 25, 2025 License: Apache-2.0 Imports: 12 Imported by: ? modules, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

README

oauth2cli example

This is an example application using oauth2cli.

To build this application,

go build

Google

Create your OAuth client.

  1. Open https://console.cloud.google.com/apis/credentials
  2. Create an OAuth client ID where the application type is other.

Run this application.

./example -client-id xxx.apps.googleusercontent.com -client-secret xxxxxxxx
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

It will automatically open the browser and you can log in to Google.

Use a TLS certificate

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.

./example -auth-url https://github.com/login/oauth/authorize -token-url https://github.com/login/oauth/access_token -client-id xxxxxxxx -client-secret xxxxxxxx
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.

Documentation

The Go Gopher

There is no documentation for this package.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL