-
Notifications
You must be signed in to change notification settings - Fork 58
/
example_test.go
61 lines (50 loc) · 1.38 KB
/
example_test.go
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
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
// Copyright 2012 Jimmy Zelinskie. All rights reserved.
// Use of this source code is governed by a BSD-style
// license that can be found in the LICENSE file.
package geddit_test
import (
"fmt"
"log"
"github.com/jzelinskie/geddit"
)
func ExampleNewOAuthSession_login() {
o, err := geddit.NewOAuthSession(
"client_id",
"client_secret",
"Testing OAuth Bot by u/my_user v0.1 see source https://github.com/jzelinskie/geddit",
"http://redirect.url",
)
if err != nil {
log.Fatal(err)
}
// Create new auth token for confidential clients (personal scripts/apps).
err = o.LoginAuth("my_user", "my_password")
if err != nil {
log.Fatal(err)
}
// Ready to make API calls!
}
func ExampleNewOAuthSession_url() {
o, err := geddit.NewOAuthSession(
"client_id",
"client_secret",
"Testing OAuth Bot by u/my_user v0.1 see source https://github.com/jzelinskie/geddit",
"http://redirect.url",
)
if err != nil {
log.Fatal(err)
}
// Pass a random/unique state string which will be returned to the
// redirect URL. Ideally, you should verify that it matches to
// avoid CSRF attack.
url := o.AuthCodeURL("random string", []string{"identity", "read"})
fmt.Printf("Visit %s to obtain auth code", url)
var code string
fmt.Scanln(&code)
// Create and set token using given auth code.
err = o.CodeAuth(code)
if err != nil {
log.Fatal(err)
}
// Ready to make API calls!
}