Skip to content

Instantly share code, notes, and snippets.

View jfcote87's full-sized avatar

Jim Cote jfcote87

View GitHub Profile
package main
import (
"golang.org/x/oauth2"
"golang.org/x/oauth2/google"
"golang.org/x/oauth2/jwt"
"log"
)
// Private key generated on my machine.
@jfcote87
jfcote87 / gist:f61a74b92192a28c0ed2
Created February 6, 2015 06:03
oauth2: User Password Authorization
func (c *Config) Authorize(ctx Context, username, password string) (TokenSource, error) {
tk, err := return retrieveToken(ctx, c, url.Values{
"grant_type": {"password"},
"username": {username},
"password": {password},
"scope": condVal(strings.Join(c.Scopes, " ")),
})
if err != nil {
return nil, err
}
@jfcote87
jfcote87 / gist:3c4550e4dedb563e9f9a
Created February 3, 2015 18:05
Example of oauth2 bug: RefreshToken not updated in TokenSource
package main
import (
"encoding/json"
"fmt"
"golang.org/x/oauth2"
"log"
"net/http"
"net/http/httptest"
"time"
package oauth2Sample
imports (
"fmt"
"log"
"net/http"
"golang.org/x/oauth2"
)