This repository was archived by the owner on Jun 27, 2020. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathdoc.go
55 lines (45 loc) · 1.47 KB
/
doc.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
// Copyright 2013 Dobrosław Żybort
//
// This Source Code Form is subject to the terms of the Mozilla Public
// License, v. 2.0. If a copy of the MPL was not distributed with this
// file, You can obtain one at http://mozilla.org/MPL/2.0/.
/*
Package oauth2 provide support for OAuth 2.0 authentication and ability
to make authenticated HTTP requests.
Check /examples/ folder for usages.
// Initialize service.
service := oauth2.Service(
YOUR_CLIENT_ID,
YOUR_CLIENT_SECRET,
"https://github.com/login/oauth/authorize",
"https://github.com/login/oauth/access_token"
)
// Set custom redirect
service.RedirectURL = "http://you.example.org/handler"
// Get authorization url.
authUrl := service.GetAuthorizeURL("")
// Send user to authUrl and get code
code := "..."
// Get access token.
token, err := service.GetAccessToken(code)
if err != nil {
log.Fatal("Get access token error: ", err)
}
// Prepare resource request.
apiBaseURL = "https://api.github.com/"
github := oauth2.Request(apiBaseURL, token.AccessToken)
github.AccessTokenInHeader = true
github.AccessTokenInHeaderScheme = "token"
//github.AccessTokenInURL = true
// Make the request.
// Provide API end point (http://developer.github.com/v3/users/#get-the-authenticated-user)
apiEndPoint := "user"
githubUserData, err := github.Get(apiEndPoint)
if err != nil {
log.Fatal("Get: ", err)
}
defer githubUserData.Body.Close()
Requests or bugs?
https://github.com/gosimple/oauth2/issues
*/
package oauth2