-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathuserauth.go
More file actions
44 lines (36 loc) · 1.13 KB
/
userauth.go
File metadata and controls
44 lines (36 loc) · 1.13 KB
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
package kuruvi
import (
"log"
"net/http"
"github.com/garyburd/go-oauth/oauth"
)
type userAuth struct {
*Auth
oauthClient oauth.Client
}
func newUserAuth(consumerKey, consumerSecret, accessTokenKey, accessTokenSecret string) *userAuth {
u := &userAuth{Auth: &Auth{
ConsumerKey: consumerKey,
ConsumerSecret: consumerSecret,
AccessTokenKey: accessTokenKey,
AccessTokenSecret: accessTokenSecret,
}}
u.oauthClient = oauth.Client{
TemporaryCredentialRequestURI: "https://api.twitter.com/oauth/request_token",
ResourceOwnerAuthorizationURI: "https://api.twitter.com/oauth/authenticate",
TokenRequestURI: "https://api.twitter.com/oauth/access_token",
}
return u
}
func (u *userAuth) setAuthHeader(req *http.Request) {
u.oauthClient.Credentials.Token = u.ConsumerKey
u.oauthClient.Credentials.Secret = u.ConsumerSecret
credentials := &oauth.Credentials{Token: u.AccessTokenKey, Secret: u.AccessTokenSecret}
err := u.oauthClient.SetAuthorizationHeader(req.Header, credentials, req.Method, req.URL, req.Form)
if err != nil {
log.Fatal(err, req)
}
}
func (u *userAuth) getAuthType() int {
return User
}