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
.

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