Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Skarlso/google-oauth-go-sample

Repository files navigation

Google OAuth Go Sample

Installation

git clone https://github.com/Skarlso/google-oauth-go-sample
cd google-oauth-go-sample
go mod download

Setup

Google

In order for the Google Authentication to work, you'll need developer credentials which this application gathers from a file in the root directory called creds.json. The structure of this file should be like this:

{
 "installed": {
 "client_id": "hash.apps.googleusercontent.com",
 "project_id": "random",
 "auth_uri": "https://accounts.google.com/o/oauth2/auth",
 "token_uri": "https://oauth2.googleapis.com/token",
 "auth_provider_x509_cert_url": "https://www.googleapis.com/oauth2/v1/certs",
 "client_secret": "secret",
 "redirect_uris": [
 "http://localhost"
 ]
 }
}

To get these credentials:

  1. Go to the Google Cloud Console
  2. Create a new project or select an existing one
  3. Enable the Google+ API
  4. Go to "Credentials" → "Create Credentials" → "OAuth 2.0 Client ID"
  5. Choose "Web application" as the application type
  6. Add http://127.0.0.1:9090/auth to "Authorized redirect URIs"
  7. Download the credentials as creds.json and place it in the project root

Note:: The application uses a FIXED session key for development. In production, set a secure 32-byte session key via environment variable or configuration.

Running

# Build the application
go build .
# Run the server
./google-oauth-go-sample

Then navigate to http://127.0.0.1:9090 in your browser.

The protected area is /battle/field.

Showcase

welcome error logged-in battle logout

About

This is a sample repository for doing Google OAuth in Go with a Web App

Topics

Resources

License

Stars

Watchers

Forks

Packages

No packages published

Contributors 2

AltStyle によって変換されたページ (->オリジナル) /