In using Go-endpoints in google app-engine, when i try to fetch the user from current context i get "No token in the current context" error.
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
}
In the getCurrentUser in endpoints.CurrentUser it gives "No token in the current context" error. What could be the problem ?