本文整理汇总了Golang中code/google/com/p/goauth2/oauth.Token类的典型用法代码示例。如果您正苦于以下问题:Golang Token类的具体用法?Golang Token怎么用?Golang Token使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了Token类的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Golang代码示例。
示例1: Token
func (c OAuthCache) Token() (*oauth.Token, error) {
var tok oauth.Token
c.bucket.Get(fmt.Sprintf("authtoken-%s", c.session["authtoken"]), &tok)
if tok.Expired() || tok.AccessToken == "" {
return nil, errors.New("No AccessToken available")
}
return &tok, nil
}
开发者ID:xeb,项目名称:flowdle,代码行数:8,代码来源:oauthcache.go
示例2: people
// people fetches the list of people user has shared with this app
func people(w http.ResponseWriter, r *http.Request) {
c := appengine.NewContext(r)
//client := urlfetch.Client(c)
session, err := store.Get(r, "sessionName")
if err != nil {
c.Infof("error fetching session: %v", err)
serveAppError(c, w, &appError{err, "Error fetching session", 500})
return
}
token := session.Values["accessToken"]
// Only fetch a list of people for connected users
if token == nil {
m := "Current user not connected"
serveAppError(c, w, &appError{errors.New(m), m, 401})
return
}
t := &oauth.Transport{Config: config,
Transport: &urlfetch.Transport{Context: c},
}
tok := new(oauth.Token)
tok.AccessToken = token.(string)
t.Token = tok
service, err := plus.New(t.Client())
if err != nil {
serveAppError(c, w, &appError{err, "Create Plus Client", 500})
return
}
// Get a list of people that this user has shared with this app
people := service.People.List("me", "visible")
peopleFeed, err := people.Do()
if err != nil {
m := "Failed to refresh access token"
if err.Error() == "AccessTokenRefreshError" {
serveAppError(c, w, &appError{errors.New(m), m, 500})
return
}
serveAppError(c, w, &appError{err, m, 500})
return
}
w.Header().Set("Content-type", "application/json")
err = json.NewEncoder(w).Encode(&peopleFeed)
if err != nil {
serveAppError(c, w, &appError{err, "Convert PeopleFeed to JSON", 500})
}
}
开发者ID:powerje,项目名称:gplus-quickstart-go,代码行数:53,代码来源:main.go
示例3: people
func people(w http.ResponseWriter, r *http.Request) *appError {
log.Printf("Responding to request %s with people handler", r.URL.Path)
session, err := store.Get(r, "DigitalCampusSession")
if err != nil {
log.Println("error fetching session:", err)
return &appError{err, "Error fetching session", http.StatusInternalServerError}
}
token := session.Values["accessToken"]
// Only fetch a list of people for connected users
if token == nil {
m := "Current user not connected"
return &appError{errors.New(m), m, http.StatusUnauthorized}
}
// Create a new authorized API client
t := &oauth.Transport{Config: config}
tok := new(oauth.Token)
tok.AccessToken = token.(string)
t.Token = tok
service, err := plus.New(t.Client())
if err != nil {
return &appError{err, "Create Plus Client", http.StatusInternalServerError}
}
// Get a list of people that this user has shared with this app
people := service.People.List("me", "visible")
peopleFeed, err := people.Do()
if err != nil {
m := "Failed to refresh access token"
if err.Error() == "AccessTokenRefreshError" {
return &appError{errors.New(m), m, http.StatusInternalServerError}
}
return &appError{err, m, http.StatusInternalServerError}
}
w.Header().Set("Content-Type", "application/json")
err = json.NewEncoder(w).Encode(&peopleFeed)
if err != nil {
return &appError{err, "Convert PeopleFeed to JSON", http.StatusInternalServerError}
}
log.Printf("Successfully handled request %s", r.URL.Path)
return nil
}
开发者ID:novaroma,项目名称:digitalcampus,代码行数:42,代码来源:main.go
示例4: PutToken
func (c *DBTokenCache) PutToken(t *goauth2.Token) error {
if t.AccessToken == "" {
return ErrEmptyAccessToken
}
var email string
if t.Extra == nil || t.Extra["email"] == "" {
conf, err := c.scheme.loadConfig()
if err != nil {
return err
}
transport := &goauth2.Transport{Config: &conf}
transport.Token = t
client := transport.Client()
response, err := client.Get(c.scheme.InfoUrl)
if err != nil {
return err
}
defer response.Body.Close()
email, err = c.scheme.Parser.Parse(response)
if email == "" {
return ErrEmptyUserEmail
}
user, err := auth.GetUserByEmail(email)
if err != nil {
if err != auth.ErrUserNotFound {
return err
}
registrationEnabled, _ := config.GetBool("auth:user-registration")
if !registrationEnabled {
return err
}
user = &auth.User{Email: email}
err := user.Create()
if err != nil {
return err
}
}
err = user.CreateOnGandalf()
if err != nil {
log.Errorf("Ignored error trying to create user on gandalf: %s", err.Error())
}
t.Extra = make(map[string]string)
t.Extra["email"] = email
}
return makeToken(t).save()
}
开发者ID:rualatngua,项目名称:tsuru,代码行数:46,代码来源:oauth.go
注:本文中的code/google/com/p/goauth2/oauth.Token类示例整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论