在app-engine中的Go端点中获取用户时获取“当前上下文中没有令牌”

时间:2015-02-10 18:54:21

标签: google-app-engine go google-cloud-endpoints

在谷歌应用引擎中使用Go-endpoints时,当我尝试从当前上下文中获取用户时,我得到“当前上下文中没有令牌”错误。

var (
    scopes    = []string{endpoints.EmailScope}
    clientIds = []string{clientId, endpoints.APIExplorerClientID}
    audiences = []string{clientId}
)

type FlightAppApi struct{
    }

func ( flightApi *FlightAppApi ) RegisterNewUser ( r *http.Request, req *UserReq, resp *User ) error {
    c := endpoints.NewContext( r )
    u, err := getCurrentUser( c )
    if err == nil {
        newUserKey := datastore.NewKey( c, "User", u.ID, 0, nil )
        newUser := &User{ UserName: req.UserName, EmailId: u.Email }
        _, err := datastore.Put( c, newUserKey, newUser )
        return err
        }
    return err
}

func getCurrentUser(c endpoints.Context) (*user.User, error) {
     u, err := endpoints.CurrentUser(c, scopes, audiences, clientIds)
     if err != nil {
         return nil, err
     }
     if u == nil {
         return nil, errors.New("Unauthorized: Please, sign in.")
    }
    c.Debugf("Current user: %#v", u)
    return u, nil
 }

在endpoints.CurrentUser中的getCurrentUser中,它给出了“当前上下文中没有令牌”错误。可能是什么问题?

0 个答案:

没有答案