Created
March 27, 2015 08:17
-
-
Save roosmaa/3518543a9ebba06bbc10 to your computer and use it in GitHub Desktop.
Clef login in Go
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package main | |
import ( | |
"encoding/json" | |
"fmt" | |
"golang.org/x/oauth2" | |
) | |
func main() { | |
code := "code" | |
conf := &oauth2.Config{ | |
ClientID: "app_id", | |
ClientSecret: "app_secret", | |
Endpoint: oauth2.Endpoint{ | |
TokenURL: "https://clef.io/api/v1/authorize", | |
}, | |
} | |
tok, err := conf.Exchange(oauth2.NoContext, code) | |
if err != nil { | |
fmt.Printf("Failed to resolve OAuth code '%s' to token: %v\n", code, err) | |
return | |
} | |
client := conf.Client(oauth2.NoContext, tok) | |
resp, err := client.Get("https://clef.io/api/v1/info") | |
if err != nil { | |
fmt.Printf("Failed to get Clef user information: %v\n", err) | |
return | |
} | |
defer resp.Body.Close() | |
info := make(map[string]interface{}) | |
if err := json.NewDecoder(resp.Body).Decode(&info); err != nil { | |
fmt.Printf("Failed to parse Clef user information response: %v\n", err) | |
return | |
} | |
fmt.Println(info) | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment