OAuth-2.0-google-cloud-storage-api-over-NATS/

directory
v0.0.0-...-a2a1f02 Latest Latest
Warning

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

Go to latest
Published: Dec 1, 2020 License: MIT

README

OAuth-2.0-google-cloud-storage-api-over-NATS

*** UNDER CONSTRUCTION - CHECK BACK SOON ***

Using OAuth 2.0 (frontend and backend via protobuf over NATS) to access a users google cloud storage (based on scopes) via googles api.

GitHub Webpage

REFRESH TOKEN

You only get refresh token once. So you must save it. User must revoke privileges here in order to get a new refresh token.

config := &oauth2.Config{
    ClientID:     cs.Web.ClientID,
    ClientSecret: cs.Web.ClientSecret,
    Endpoint: oauth2.Endpoint{
    TokenURL: "https://accounts.google.com/o/oauth2/token",
    },
}

restoredToken := &oauth2.Token{
    AccessToken:  token.AccessToken,
    RefreshToken: token.RefreshToken,
    Expiry:       token.Expiry,
    TokenType:    token.TokenType,
}

tokenSource := config.TokenSource(oauth2.NoContext, restoredToken)
client := oauth2.NewClient(oauth2.NoContext, tokenSource)
token, err = tokenSource.Token()

// Now use it in the api call
response, err "= client.Get("https://www.googleapis.com/storage/v1/b?project=PROJECT_NAME")

HIGH-LEVEL VIEW

This example expands on OAuth-2.0-google-cloud-storage-api and adds protobuf and NATS to pass auth code from front-end to back-end.

IMAGE - OAuth-2.0-web-server-app-authorization-flow - IMAGE

RUN

Boot up a NATS server such as,

gnatsd -DV -addr localhost --port 4222

Run both the frontend and backend processes,

cd frontend
go run client.go messages.pb.go
cd backend
go run server.go messages.pb.go

Then use by going to a browser,

http://127.0.0.1:3000

Directories

Path Synopsis
Package main is a generated protocol buffer package.
Package main is a generated protocol buffer package.
Package main is a generated protocol buffer package.
Package main is a generated protocol buffer package.
Package main is a generated protocol buffer package.
Package main is a generated protocol buffer package.

Jump to

Keyboard shortcuts

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