~thrrgilag/woodstock

woodstock/examples/auth.go -rw-r--r-- 501 bytes
62b10b5cMorgan McMillian Update for new project location and module name 5 months ago
                                                                                
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
package main

import (
	"fmt"

	"mcmillian.dev/go/woodstock"
)

const (
	CLIENT_ID     = "client id"
	CLIENT_SECRET = "client secret"
	REDIRECT_URI  = "redirect uri"
)

func main() {
	client := woodstock.NewClient(CLIENT_ID, CLIENT_SECRET)
	fmt.Println(client.AuthURL(REDIRECT_URI, []string{"basic"}, "code"))
	fmt.Print("> ")

	var code string
	fmt.Scan(&code)

	result, err := client.AccessToken(code, REDIRECT_URI)
	if err != nil {
		fmt.Println(err)
		return
	}
	fmt.Println(result.AccessToken)
}