Coder Social home page Coder Social logo

oauth2's People

Contributors

ahmetb avatar asazernik avatar codegangsta avatar dougbarrett avatar exaspark avatar jakejscott avatar jaredgisin avatar rakyll avatar sorah avatar tomsteele avatar weslleyandrade avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

oauth2's Issues

Adding oauth2 providers

What is the policy about adding oauth2 providers? I've integrated linkedin locally and wondering if it's worth doing a pull request...a small modification I had to make was linkedin absolutely always requires a state so the root "/" is used if non is provided via ?next=, but beyond that it was just a matter of adding in the oauth2 endpoints.

oauth2.go:51: undefined: oauth2.Options

> go get github.com/martini-contrib/oauth2
# github.com/martini-contrib/oauth2
src/github.com/martini-contrib/oauth2/oauth2.go:51: undefined: oauth2.Options

> go run server.go 
# github.com/martini-contrib/oauth2
src/github.com/martini-contrib/oauth2/oauth2.go:51: undefined: oauth2.Options

> go version
go version go1.3.3 linux/amd64

Delete the repo?

Is it possible to delete the repo since we don't maintain it and don't recommend anyone to use Martini? I contributed two plugins to dogfood the framework but they keep appearing on the list of projects I have contributed on my Github profile and got highlighted occasionally as they are my best work :(

I have more responsibilities for the Go project now and I am now often being asked why I even contributed to Martini in the first place by those who don't have context. I desperately desire to free myself from this stigma and any help is appreciated.

Any thoughts?

/cc @codegangsta

(Hoping no offenses are taken. Tech industry is unfortunately not a harassment-free space, hence there is this bug.)

martini-contrib/oauth2 is unsafe and vulnerable to csrf

the oauth2 "state" field, the first argument of AuthCodeURL, is supposed to be a CSRF token - a completely unguessable random string of bytes. further, on the callback, the oauth2 service will return the provided state and negroni-oauth2 should be checking it for equality

it's certainly clever that the next url is being passed in as the state field, but it's insecure. both the expected state and the next url should be kept in the session

http://tools.ietf.org/html/rfc6749#section-10.12

it may be safe to include additional information inside the state field besides a csrf token (e.g. the next url field), but any benefit from that is possibly negated by having to store the expected csrf token somewhere

check out https://github.com/jtolds/go-oauth2http

Github Missing Access Token

Was trying out the code from #18 when I stumbled on what looks like code.google.com/p/goauth2 not storing the access_token from Github. Both / and /login render nothing for tokens.Access().

package main

import (
  "github.com/go-martini/martini"
  "github.com/martini-contrib/oauth2"
  "github.com/martini-contrib/sessions"
)

func main() {

  m := martini.Classic()
  m.Use(sessions.Sessions("sess", sessions.NewCookieStore([]byte("qwerty"))))
  m.Use(oauth2.Github(&oauth2.Options{
    ClientId:     "xxx",
    ClientSecret: "xxx",
    RedirectURL:  "http://localhost:3000",
  }))

  m.Get("/", func(tokens oauth2.Tokens) string {
    if tokens.IsExpired() {
      return "not logged in, or the access token is expired"
    }
    return "logged in " + tokens.Access() + "."
  })

  m.Get("/login", oauth2.LoginRequired, func(tokens oauth2.Tokens) string {
    return tokens.Access()
  })

  m.Get("/logout", func(sess sessions.Session) string {
    sess.Clear()
    return "cleared!"
  })

  m.Run()
}

Twitter oauth2

@mvader Twitter oauth2 will not work in this context. Twitter only offers a partial oauth2 implementation which works differently to the more common oauth2 implementations i.e. Facebook, Google etc.

For user login, Twitter still requires oauth1. Hopefully that will change before too long.

Bugs in documentation

Found a bug in the docs.

The way golang/oauth2 is referenced in line 12 does not work in my go version go1.3 darwin/amd64 . I get the following error:

 $ go run test.go 
# command-line-arguments
./test.go:12: undefined: "github.com/martini-contrib/oauth2".Options

I had to create a new reference? to that library to get to the Options type.
0782b77

How do you optionally require the login redirect?

Question: If I have an API that only requires a login redirect if additional parameters are added, how would this be written?

For example, if I set up:

m.Use(oauth2.Google(oauth2.Options{...}))
m.Get("/api/getstuff", apiGetStuff)  // no login redirect required generally
...
func apiGetStuff(w ..., r ..., tokens oauth2.Tokens, req ...) string {
    if req.FormValue("filter") == "mine" { // Require authentication
        // Call oauth2.LoginRedirect here to populate 'tokens' information
        if tokens.IsExpired() {
            return tokens.Access()
        }
    }
...

How can I call oauth2.LoginRedirect to fill in the tokens information only when I need the call to be authenticated?

Testing GitHub OAuth locally

Hi,

I have a simple Go application like in readme file. I created a Github application with http://localhost:3000 callback url.

When I visit http://localhost:3000/restrict it redirects me to something like: http://localhost:3000/?code=4879ba4e9e5c5291bafe&state=%2Frestrict after authorizing github application and shows me "not logged in, or the access token is expired".

package main

import (
  "github.com/go-martini/martini"
  "github.com/martini-contrib/oauth2"
  "github.com/martini-contrib/sessions"
)

func main() {
  m := martini.Classic()
  m.Use(sessions.Sessions("my_session", sessions.NewCookieStore([]byte("secret123"))))
  m.Use(oauth2.Github(&oauth2.Options{
    ClientId:     "Client ID from Github application",
    ClientSecret: "Client Secret from Github application",
    RedirectURL:  "http://localhost:3000",
  }))

  // Tokens are injected to the handlers
  m.Get("/", func(tokens oauth2.Tokens) string {
    if tokens.IsExpired() {
      return "not logged in, or the access token is expired"
    }
    return "logged in"
  })

  // Routes that require a logged in user
  // can be protected with oauth2.LoginRequired handler.
  // If the user is not authenticated, they will be
  // redirected to the login path.
  m.Get("/restrict", oauth2.LoginRequired, func(tokens oauth2.Tokens) string {
    return tokens.Access()
  })

  m.Run()
}

So in my github settings I have this app authorized. But can't log in.
Could you guys help? What I did wrong?

Problem with "go get github.com/martini-contrib/oauth2"

When I try get the oauth2 package the console return this for me:

$ go get github.com/martini-contrib/oauth2
# github.com/martini-contrib/oauth2
../../go/src/src/github.com/martini-contrib/oauth2/oauth2.go:181: not enough arguments in call to c.AuthCodeURL

Handling multiple oauth authentication

This is more of question/suggestion than a ticket. Since the oauth func writes to the response on failure, it seems impossible to use multiple oauth/auth for a martini app since the first auth handler to fail will end the request cycle. It would be nice to provide an extra skip parameter to oauth2.LoginRequired to indicate whether it should skip on the next handler on failure or not. This will allow for chaining of multiple auth handlers (fb, google, etc)

If there is a way to chain multiple auth handlers with the current implementation, I would be happy if someone can point me to any doc/code sample.

New problem with "go get github.com/martini-contrib/oauth2"

I cannot install the package, see:

Project hg: ⎇ default r  
> go get github.com/martini-contrib/sessions
Project hg: ⎇ default r  
> go get github.com/martini-contrib/oauth2
package github.com/martini-contrib/oauth2
        imports github.com/golang/oauth2
        imports github.com/golang/oauth2
        imports github.com/golang/oauth2: code in directory /home/jorge/go-workspace/src/github.com/golang/oauth2 expects import "golang.org/x/oauth2"                                                                                                                                 
Project hg: ⎇ default r  
> go get golang.org/x/oauth2
Project hg: ⎇ default r  
> go get github.com/martini-contrib/oauth2
../../../github.com/martini-contrib/oauth2/oauth2.go:27:2: code in directory /home/jorge/go-workspace/src/github.com/golang/oauth2 expects import "golang.org/x/oauth2"                                                                                                                
Project hg: ⎇ default r  
> 

/oauth2callback stack overflow

I've updated to the latest go 1.3.3 to ensure there's no compatibility issues, and have updated the sessions, oauth2 and martini oauth2 packages and have tested with Google login and Github login and am getting the same issues, where I'm able to login and it shows the scopes I want to select, but as soon as I hit oauth2callback it starts doing something that causes a stack overflow, here is the output:

Dougs-MacBook-Pro:backend dougbarrett$ gin
[gin] listening on port 3000
[martini] listening on :3001 (development)
[martini] Started GET / for ::1
[martini] Completed 200 OK in 348.857us
[martini] Started GET / for ::1
[martini] Completed 200 OK in 459.203us
[martini] Started GET /login for ::1
[martini] Completed 302 Found in 124.33us
[martini] Started GET /oauth2callback for ::1
runtime: goroutine stack exceeds 1000000000-byte limit
fatal error: stack overflow

runtime stack:
runtime.throw(0x59dfae)
    /usr/local/go/src/pkg/runtime/panic.c:520 +0x69
runtime.newstack()
    /usr/local/go/src/pkg/runtime/stack.c:770 +0x486
runtime.morestack()
    /usr/local/go/src/pkg/runtime/asm_amd64.s:228 +0x61

goroutine 20 [stack growth]:
github.com/martini-contrib/oauth2.(*token).Expired(0xc2080e0360, 0x0)
    /Users/dougbarrett/goapps/src/github.com/martini-contrib/oauth2/oauth2.go:76 fp=0xc2683500f8 sp=0xc2683500f0
github.com/martini-contrib/oauth2.(*token).Expired(0xc2080e0360, 0x0)
    /Users/dougbarrett/goapps/src/github.com/martini-contrib/oauth2/oauth2.go:80 +0x39 fp=0xc268350110 sp=0xc2683500f8
github.com/martini-contrib/oauth2.(*token).Expired(0xc2080e0360, 0x0)
    /Users/dougbarrett/goapps/src/github.com/martini-contrib/oauth2/oauth2.go:80 +0x39 fp=0xc268350128 sp=0xc268350110
github.com/martini-contrib/oauth2.(*token).Expired(0xc2080e0360, 0x0)
    /Users/dougbarrett/goapps/src/github.com/martini-contrib/oauth2/oauth2.go:80 +0x39 fp=0xc268350140 sp=0xc268350128
github.com/martini-contrib/oauth2.(*token).Expired(0xc2080e0360, 0x0)
    /Users/dougbarrett/goapps/src/github.com/martini-contrib/oauth2/oauth2.go:80 +0x39 fp=0xc268350158 sp=0xc268350140
github.com/martini-contrib/oauth2.(*token).Expired(0xc2080e0360, 0x0)
    /Users/dougbarrett/goapps/src/github.com/martini-contrib/oauth2/oauth2.go:80 +0x39 fp=0xc268350170 sp=0xc268350158
github.com/martini-contrib/oauth2.(*token).Expired(0xc2080e0360, 0x0)
    /Users/dougbarrett/goapps/src/github.com/martini-contrib/oauth2/oauth2.go:80 +0x39 fp=0xc268350188 sp=0xc268350170
github.com/martini-contrib/oauth2.(*token).Expired(0xc2080e0360, 0x0)
    /Users/dougbarrett/goapps/src/github.com/martini-contrib/oauth2/oauth2.go:80 +0x39 fp=0xc2683501a0 sp=0xc268350188
github.com/martini-contrib/oauth2.(*token).Expired(0xc2080e0360, 0x0)
    /Users/dougbarrett/goapps/src/github.com/martini-contrib/oauth2/oauth2.go:80 +0x39 fp=0xc2683501b8 sp=0xc2683501a0
github.com/martini-contrib/oauth2.(*token).Expired(0xc2080e0360, 0x0)
    /Users/dougbarrett/goapps/src/github.com/martini-contrib/oauth2/oauth2.go:80 +0x39 fp=0xc2683501d0 sp=0xc2683501b8
github.com/martini-contrib/oauth2.(*token).Expired(0xc2080e0360, 0x0)
    /Users/dougbarrett/goapps/src/github.com/martini-contrib/oauth2/oauth2.go:80 +0x39 fp=0xc2683501e8 sp=0xc2683501d0
github.com/martini-contrib/oauth2.(*token).Expired(0xc2080e0360, 0x0)
    /Users/dougbarrett/goapps/src/github.com/martini-contrib/oauth2/oauth2.go:80 +0x39 fp=0xc268350200 sp=0xc2683501e8
github.com/martini-contrib/oauth2.(*token).Expired(0xc2080e0360, 0x0)
    /Users/dougbarrett/goapps/src/github.com/martini-contrib/oauth2/oauth2.go:80 +0x39 fp=0xc268350218 sp=0xc268350200
github.com/martini-contrib/oauth2.(*token).Expired(0xc2080e0360, 0x0)
    /Users/dougbarrett/goapps/src/github.com/martini-contrib/oauth2/oauth2.go:80 +0x39 fp=0xc268350230 sp=0xc268350218
github.com/martini-contrib/oauth2.(*token).Expired(0xc2080e0360, 0x0)
    /Users/dougbarrett/goapps/src/github.com/martini-contrib/oauth2/oauth2.go:80 +0x39 fp=0xc268350248 sp=0xc268350230
github.com/martini-contrib/oauth2.(*token).Expired(0xc2080e0360, 0x0)
    /Users/dougbarrett/goapps/src/github.com/martini-contrib/oauth2/oauth2.go:80 +0x39 fp=0xc268350260 sp=0xc268350248
github.com/martini-contrib/oauth2.(*token).Expired(0xc2080e0360, 0x0)
    /Users/dougbarrett/goapps/src/github.com/martini-contrib/oauth2/oauth2.go:80 +0x39 fp=0xc268350278 sp=0xc268350260
github.com/martini-contrib/oauth2.(*token).Expired(0xc2080e0360, 0x0)
    /Users/dougbarrett/goapps/src/github.com/martini-contrib/oauth2/oauth2.go:80 +0x39 fp=0xc268350290 sp=0xc268350278
github.com/martini-contrib/oauth2.(*token).Expired(0xc2080e0360, 0x0)
    /Users/dougbarrett/goapps/src/github.com/martini-contrib/oauth2/oauth2.go:80 +0x39 fp=0xc2683502a8 sp=0xc268350290
github.com/martini-contrib/oauth2.(*token).Expired(0xc2080e0360, 0x0)
    /Users/dougbarrett/goapps/src/github.com/martini-contrib/oauth2/oauth2.go:80 +0x39 fp=0xc2683502c0 sp=0xc2683502a8
github.com/martini-contrib/oauth2.(*token).Expired(0xc2080e0360, 0x0)
    /Users/dougbarrett/goapps/src/github.com/martini-contrib/oauth2/oauth2.go:80 +0x39 fp=0xc2683502d8 sp=0xc2683502c0
github.com/martini-contrib/oauth2.(*token).Expired(0xc2080e0360, 0x0)
    /Users/dougbarrett/goapps/src/github.com/martini-contrib/oauth2/oauth2.go:80 +0x39 fp=0xc2683502f0 sp=0xc2683502d8
github.com/martini-contrib/oauth2.(*token).Expired(0xc2080e0360, 0x0)
    /Users/dougbarrett/goapps/src/github.com/martini-contrib/oauth2/oauth2.go:80 +0x39 fp=0xc268350308 sp=0xc2683502f0
github.com/martini-contrib/oauth2.(*token).Expired(0xc2080e0360, 0x0)
    /Users/dougbarrett/goapps/src/github.com/martini-contrib/oauth2/oauth2.go:80 +0x39 fp=0xc268350320 sp=0xc268350308
github.com/martini-contrib/oauth2.(*token).Expired(0xc2080e0360, 0x0)
    /Users/dougbarrett/goapps/src/github.com/martini-contrib/oauth2/oauth2.go:80 +0x39 fp=0xc268350338 sp=0xc268350320
github.com/martini-contrib/oauth2.(*token).Expired(0xc2080e0360, 0x0)
    /Users/dougbarrett/goapps/src/github.com/martini-contrib/oauth2/oauth2.go:80 +0x39 fp=0xc268350350 sp=0xc268350338
github.com/martini-contrib/oauth2.(*token).Expired(0xc2080e0360, 0x0)
    /Users/dougbarrett/goapps/src/github.com/martini-contrib/oauth2/oauth2.go:80 +0x39 fp=0xc268350368 sp=0xc268350350
github.com/martini-contrib/oauth2.(*token).Expired(0xc2080e0360, 0x0)
    /Users/dougbarrett/goapps/src/github.com/martini-contrib/oauth2/oauth2.go:80 +0x39 fp=0xc268350380 sp=0xc268350368
github.com/martini-contrib/oauth2.(*token).Expired(0xc2080e0360, 0x0)
    /Users/dougbarrett/goapps/src/github.com/martini-contrib/oauth2/oauth2.go:80 +0x39 fp=0xc268350398 sp=0xc268350380
github.com/martini-contrib/oauth2.(*token).Expired(0xc2080e0360, 0x0)
    /Users/dougbarrett/goapps/src/github.com/martini-contrib/oauth2/oauth2.go:80 +0x39 fp=0xc2683503b0 sp=0xc268350398
github.com/martini-contrib/oauth2.(*token).Expired(0xc2080e0360, 0x0)
    /Users/dougbarrett/goapps/src/github.com/martini-contrib/oauth2/oauth2.go:80 +0x39 fp=0xc2683503c8 sp=0xc2683503b0
github.com/martini-contrib/oauth2.(*token).Expired(0xc2080e0360, 0x0)
    /Users/dougbarrett/goapps/src/github.com/martini-contrib/oauth2/oauth2.go:80 +0x39 fp=0xc2683503e0 sp=0xc2683503c8
github.com/martini-contrib/oauth2.(*token).Expired(0xc2080e0360, 0x0)
    /Users/dougbarrett/goapps/src/github.com/martini-contrib/oauth2/oauth2.go:80 +0x39 fp=0xc2683503f8 sp=0xc2683503e0
github.com/martini-contrib/oauth2.(*token).Expired(0xc2080e0360, 0x0)
    /Users/dougbarrett/goapps/src/github.com/martini-contrib/oauth2/oauth2.go:80 +0x39 fp=0xc268350410 sp=0xc2683503f8
github.com/martini-contrib/oauth2.(*token).Expired(0xc2080e0360, 0x0)
    /Users/dougbarrett/goapps/src/github.com/martini-contrib/oauth2/oauth2.go:80 +0x39 fp=0xc268350428 sp=0xc268350410
github.com/martini-contrib/oauth2.(*token).Expired(0xc2080e0360, 0x0)
    /Users/dougbarrett/goapps/src/github.com/martini-contrib/oauth2/oauth2.go:80 +0x39 fp=0xc268350440 sp=0xc268350428
github.com/martini-contrib/oauth2.(*token).Expired(0xc2080e0360, 0x0)
    /Users/dougbarrett/goapps/src/github.com/martini-contrib/oauth2/oauth2.go:80 +0x39 fp=0xc268350458 sp=0xc268350440
github.com/martini-contrib/oauth2.(*token).Expired(0xc2080e0360, 0x0)
    /Users/dougbarrett/goapps/src/github.com/martini-contrib/oauth2/oauth2.go:80 +0x39 fp=0xc268350470 sp=0xc268350458
github.com/martini-contrib/oauth2.(*token).Expired(0xc2080e0360, 0x0)
    /Users/dougbarrett/goapps/src/github.com/martini-contrib/oauth2/oauth2.go:80 +0x39 fp=0xc268350488 sp=0xc268350470
github.com/martini-contrib/oauth2.(*token).Expired(0xc2080e0360, 0x0)
    /Users/dougbarrett/goapps/src/github.com/martini-contrib/oauth2/oauth2.go:80 +0x39 fp=0xc2683504a0 sp=0xc268350488
github.com/martini-contrib/oauth2.(*token).Expired(0xc2080e0360, 0x0)
    /Users/dougbarrett/goapps/src/github.com/martini-contrib/oauth2/oauth2.go:80 +0x39 fp=0xc2683504b8 sp=0xc2683504a0
github.com/martini-contrib/oauth2.(*token).Expired(0xc2080e0360, 0x0)
    /Users/dougbarrett/goapps/src/github.com/martini-contrib/oauth2/oauth2.go:80 +0x39 fp=0xc2683504d0 sp=0xc2683504b8
github.com/martini-contrib/oauth2.(*token).Expired(0xc2080e0360, 0x0)
    /Users/dougbarrett/goapps/src/github.com/martini-contrib/oauth2/oauth2.go:80 +0x39 fp=0xc2683504e8 sp=0xc2683504d0
github.com/martini-contrib/oauth2.(*token).Expired(0xc2080e0360, 0x0)
    /Users/dougbarrett/goapps/src/github.com/martini-contrib/oauth2/oauth2.go:80 +0x39 fp=0xc268350500 sp=0xc2683504e8
github.com/martini-contrib/oauth2.(*token).Expired(0xc2080e0360, 0x0)
    /Users/dougbarrett/goapps/src/github.com/martini-contrib/oauth2/oauth2.go:80 +0x39 fp=0xc268350518 sp=0xc268350500
github.com/martini-contrib/oauth2.(*token).Expired(0xc2080e0360, 0x0)
    /Users/dougbarrett/goapps/src/github.com/martini-contrib/oauth2/oauth2.go:80 +0x39 fp=0xc268350530 sp=0xc268350518
github.com/martini-contrib/oauth2.(*token).Expired(0xc2080e0360, 0x0)
    /Users/dougbarrett/goapps/src/github.com/martini-contrib/oauth2/oauth2.go:80 +0x39 fp=0xc268350548 sp=0xc268350530
github.com/martini-contrib/oauth2.(*token).Expired(0xc2080e0360, 0x0)
    /Users/dougbarrett/goapps/src/github.com/martini-contrib/oauth2/oauth2.go:80 +0x39 fp=0xc268350560 sp=0xc268350548
github.com/martini-contrib/oauth2.(*token).Expired(0xc2080e0360, 0x0)
    /Users/dougbarrett/goapps/src/github.com/martini-contrib/oauth2/oauth2.go:80 +0x39 fp=0xc268350578 sp=0xc268350560
github.com/martini-contrib/oauth2.(*token).Expired(0xc2080e0360, 0x0)
    /Users/dougbarrett/goapps/src/github.com/martini-contrib/oauth2/oauth2.go:80 +0x39 fp=0xc268350590 sp=0xc268350578
github.com/martini-contrib/oauth2.(*token).Expired(0xc2080e0360, 0x0)
    /Users/dougbarrett/goapps/src/github.com/martini-contrib/oauth2/oauth2.go:80 +0x39 fp=0xc2683505a8 sp=0xc268350590
github.com/martini-contrib/oauth2.(*token).Expired(0xc2080e0360, 0x0)
    /Users/dougbarrett/goapps/src/github.com/martini-contrib/oauth2/oauth2.go:80 +0x39 fp=0xc2683505c0 sp=0xc2683505a8
github.com/martini-contrib/oauth2.(*token).Expired(0xc2080e0360, 0x0)
    /Users/dougbarrett/goapps/src/github.com/martini-contrib/oauth2/oauth2.go:80 +0x39 fp=0xc2683505d8 sp=0xc2683505c0
github.com/martini-contrib/oauth2.(*token).Expired(0xc2080e0360, 0x0)
    /Users/dougbarrett/goapps/src/github.com/martini-contrib/oauth2/oauth2.go:80 +0x39 fp=0xc2683505f0 sp=0xc2683505d8
github.com/martini-contrib/oauth2.(*token).Expired(0xc2080e0360, 0x0)
    /Users/dougbarrett/goapps/src/github.com/martini-contrib/oauth2/oauth2.go:80 +0x39 fp=0xc268350608 sp=0xc2683505f0
github.com/martini-contrib/oauth2.(*token).Expired(0xc2080e0360, 0x0)
    /Users/dougbarrett/goapps/src/github.com/martini-contrib/oauth2/oauth2.go:80 +0x39 fp=0xc268350620 sp=0xc268350608
github.com/martini-contrib/oauth2.(*token).Expired(0xc2080e0360, 0x0)
    /Users/dougbarrett/goapps/src/github.com/martini-contrib/oauth2/oauth2.go:80 +0x39 fp=0xc268350638 sp=0xc268350620
github.com/martini-contrib/oauth2.(*token).Expired(0xc2080e0360, 0x0)
    /Users/dougbarrett/goapps/src/github.com/martini-contrib/oauth2/oauth2.go:80 +0x39 fp=0xc268350650 sp=0xc268350638
github.com/martini-contrib/oauth2.(*token).Expired(0xc2080e0360, 0x0)
    /Users/dougbarrett/goapps/src/github.com/martini-contrib/oauth2/oauth2.go:80 +0x39 fp=0xc268350668 sp=0xc268350650
github.com/martini-contrib/oauth2.(*token).Expired(0xc2080e0360, 0x0)
    /Users/dougbarrett/goapps/src/github.com/martini-contrib/oauth2/oauth2.go:80 +0x39 fp=0xc268350680 sp=0xc268350668
github.com/martini-contrib/oauth2.(*token).Expired(0xc2080e0360, 0x0)
    /Users/dougbarrett/goapps/src/github.com/martini-contrib/oauth2/oauth2.go:80 +0x39 fp=0xc268350698 sp=0xc268350680
github.com/martini-contrib/oauth2.(*token).Expired(0xc2080e0360, 0x0)
    /Users/dougbarrett/goapps/src/github.com/martini-contrib/oauth2/oauth2.go:80 +0x39 fp=0xc2683506b0 sp=0xc268350698
github.com/martini-contrib/oauth2.(*token).Expired(0xc2080e0360, 0x0)
    /Users/dougbarrett/goapps/src/github.com/martini-contrib/oauth2/oauth2.go:80 +0x39 fp=0xc2683506c8 sp=0xc2683506b0
github.com/martini-contrib/oauth2.(*token).Expired(0xc2080e0360, 0x0)
    /Users/dougbarrett/goapps/src/github.com/martini-contrib/oauth2/oauth2.go:80 +0x39 fp=0xc2683506e0 sp=0xc2683506c8
github.com/martini-contrib/oauth2.(*token).Expired(0xc2080e0360, 0x0)
    /Users/dougbarrett/goapps/src/github.com/martini-contrib/oauth2/oauth2.go:80 +0x39 fp=0xc2683506f8 sp=0xc2683506e0
github.com/martini-contrib/oauth2.(*token).Expired(0xc2080e0360, 0x0)
    /Users/dougbarrett/goapps/src/github.com/martini-contrib/oauth2/oauth2.go:80 +0x39 fp=0xc268350710 sp=0xc2683506f8
github.com/martini-contrib/oauth2.(*token).Expired(0xc2080e0360, 0x0)
    /Users/dougbarrett/goapps/src/github.com/martini-contrib/oauth2/oauth2.go:80 +0x39 fp=0xc268350728 sp=0xc268350710
github.com/martini-contrib/oauth2.(*token).Expired(0xc2080e0360, 0x0)
    /Users/dougbarrett/goapps/src/github.com/martini-contrib/oauth2/oauth2.go:80 +0x39 fp=0xc268350740 sp=0xc268350728
github.com/martini-contrib/oauth2.(*token).Expired(0xc2080e0360, 0x0)
    /Users/dougbarrett/goapps/src/github.com/martini-contrib/oauth2/oauth2.go:80 +0x39 fp=0xc268350758 sp=0xc268350740
github.com/martini-contrib/oauth2.(*token).Expired(0xc2080e0360, 0x0)
    /Users/dougbarrett/goapps/src/github.com/martini-contrib/oauth2/oauth2.go:80 +0x39 fp=0xc268350770 sp=0xc268350758
github.com/martini-contrib/oauth2.(*token).Expired(0xc2080e0360, 0x0)
    /Users/dougbarrett/goapps/src/github.com/martini-contrib/oauth2/oauth2.go:80 +0x39 fp=0xc268350788 sp=0xc268350770
github.com/martini-contrib/oauth2.(*token).Expired(0xc2080e0360, 0x0)
    /Users/dougbarrett/goapps/src/github.com/martini-contrib/oauth2/oauth2.go:80 +0x39 fp=0xc2683507a0 sp=0xc268350788
github.com/martini-contrib/oauth2.(*token).Expired(0xc2080e0360, 0x0)
    /Users/dougbarrett/goapps/src/github.com/martini-contrib/oauth2/oauth2.go:80 +0x39 fp=0xc2683507b8 sp=0xc2683507a0
github.com/martini-contrib/oauth2.(*token).Expired(0xc2080e0360, 0x0)
    /Users/dougbarrett/goapps/src/github.com/martini-contrib/oauth2/oauth2.go:80 +0x39 fp=0xc2683507d0 sp=0xc2683507b8
github.com/martini-contrib/oauth2.(*token).Expired(0xc2080e0360, 0x0)
    /Users/dougbarrett/goapps/src/github.com/martini-contrib/oauth2/oauth2.go:80 +0x39 fp=0xc2683507e8 sp=0xc2683507d0
github.com/martini-contrib/oauth2.(*token).Expired(0xc2080e0360, 0x0)
    /Users/dougbarrett/goapps/src/github.com/martini-contrib/oauth2/oauth2.go:80 +0x39 fp=0xc268350800 sp=0xc2683507e8
github.com/martini-contrib/oauth2.(*token).Expired(0xc2080e0360, 0x0)
    /Users/dougbarrett/goapps/src/github.com/martini-contrib/oauth2/oauth2.go:80 +0x39 fp=0xc268350818 sp=0xc268350800
github.com/martini-contrib/oauth2.(*token).Expired(0xc2080e0360, 0x0)
    /Users/dougbarrett/goapps/src/github.com/martini-contrib/oauth2/oauth2.go:80 +0x39 fp=0xc268350830 sp=0xc268350818
github.com/martini-contrib/oauth2.(*token).Expired(0xc2080e0360, 0x0)
    /Users/dougbarrett/goapps/src/github.com/martini-contrib/oauth2/oauth2.go:80 +0x39 fp=0xc268350848 sp=0xc268350830
github.com/martini-contrib/oauth2.(*token).Expired(0xc2080e0360, 0x0)
    /Users/dougbarrett/goapps/src/github.com/martini-contrib/oauth2/oauth2.go:80 +0x39 fp=0xc268350860 sp=0xc268350848
github.com/martini-contrib/oauth2.(*token).Expired(0xc2080e0360, 0x0)
    /Users/dougbarrett/goapps/src/github.com/martini-contrib/oauth2/oauth2.go:80 +0x39 fp=0xc268350878 sp=0xc268350860
github.com/martini-contrib/oauth2.(*token).Expired(0xc2080e0360, 0x0)
    /Users/dougbarrett/goapps/src/github.com/martini-contrib/oauth2/oauth2.go:80 +0x39 fp=0xc268350890 sp=0xc268350878
github.com/martini-contrib/oauth2.(*token).Expired(0xc2080e0360, 0x0)
    /Users/dougbarrett/goapps/src/github.com/martini-contrib/oauth2/oauth2.go:80 +0x39 fp=0xc2683508a8 sp=0xc268350890
github.com/martini-contrib/oauth2.(*token).Expired(0xc2080e0360, 0x0)
    /Users/dougbarrett/goapps/src/github.com/martini-contrib/oauth2/oauth2.go:80 +0x39 fp=0xc2683508c0 sp=0xc2683508a8
github.com/martini-contrib/oauth2.(*token).Expired(0xc2080e0360, 0x0)
    /Users/dougbarrett/goapps/src/github.com/martini-contrib/oauth2/oauth2.go:80 +0x39 fp=0xc2683508d8 sp=0xc2683508c0
github.com/martini-contrib/oauth2.(*token).Expired(0xc2080e0360, 0x0)
    /Users/dougbarrett/goapps/src/github.com/martini-contrib/oauth2/oauth2.go:80 +0x39 fp=0xc2683508f0 sp=0xc2683508d8
github.com/martini-contrib/oauth2.(*token).Expired(0xc2080e0360, 0x0)
    /Users/dougbarrett/goapps/src/github.com/martini-contrib/oauth2/oauth2.go:80 +0x39 fp=0xc268350908 sp=0xc2683508f0
github.com/martini-contrib/oauth2.(*token).Expired(0xc2080e0360, 0x0)
    /Users/dougbarrett/goapps/src/github.com/martini-contrib/oauth2/oauth2.go:80 +0x39 fp=0xc268350920 sp=0xc268350908
github.com/martini-contrib/oauth2.(*token).Expired(0xc2080e0360, 0x0)
    /Users/dougbarrett/goapps/src/github.com/martini-contrib/oauth2/oauth2.go:80 +0x39 fp=0xc268350938 sp=0xc268350920
github.com/martini-contrib/oauth2.(*token).Expired(0xc2080e0360, 0x0)
    /Users/dougbarrett/goapps/src/github.com/martini-contrib/oauth2/oauth2.go:80 +0x39 fp=0xc268350950 sp=0xc268350938
github.com/martini-contrib/oauth2.(*token).Expired(0xc2080e0360, 0x0)
    /Users/dougbarrett/goapps/src/github.com/martini-contrib/oauth2/oauth2.go:80 +0x39 fp=0xc268350968 sp=0xc268350950
github.com/martini-contrib/oauth2.(*token).Expired(0xc2080e0360, 0x0)
    /Users/dougbarrett/goapps/src/github.com/martini-contrib/oauth2/oauth2.go:80 +0x39 fp=0xc268350980 sp=0xc268350968
github.com/martini-contrib/oauth2.(*token).Expired(0xc2080e0360, 0x0)
    /Users/dougbarrett/goapps/src/github.com/martini-contrib/oauth2/oauth2.go:80 +0x39 fp=0xc268350998 sp=0xc268350980
github.com/martini-contrib/oauth2.(*token).Expired(0xc2080e0360, 0x0)
    /Users/dougbarrett/goapps/src/github.com/martini-contrib/oauth2/oauth2.go:80 +0x39 fp=0xc2683509b0 sp=0xc268350998
github.com/martini-contrib/oauth2.(*token).Expired(0xc2080e0360, 0x0)
    /Users/dougbarrett/goapps/src/github.com/martini-contrib/oauth2/oauth2.go:80 +0x39 fp=0xc2683509c8 sp=0xc2683509b0
github.com/martini-contrib/oauth2.(*token).Expired(0xc2080e0360, 0x0)
    /Users/dougbarrett/goapps/src/github.com/martini-contrib/oauth2/oauth2.go:80 +0x39 fp=0xc2683509e0 sp=0xc2683509c8
github.com/martini-contrib/oauth2.(*token).Expired(0xc2080e0360, 0x0)
    /Users/dougbarrett/goapps/src/github.com/martini-contrib/oauth2/oauth2.go:80 +0x39 fp=0xc2683509f8 sp=0xc2683509e0
github.com/martini-contrib/oauth2.(*token).Expired(0xc2080e0360, 0x0)
    /Users/dougbarrett/goapps/src/github.com/martini-contrib/oauth2/oauth2.go:80 +0x39 fp=0xc268350a10 sp=0xc2683509f8
github.com/martini-contrib/oauth2.(*token).Expired(0xc2080e0360, 0x0)
    /Users/dougbarrett/goapps/src/github.com/martini-contrib/oauth2/oauth2.go:80 +0x39 fp=0xc268350a28 sp=0xc268350a10
github.com/martini-contrib/oauth2.(*token).Expired(0xc2080e0360, 0x0)
    /Users/dougbarrett/goapps/src/github.com/martini-contrib/oauth2/oauth2.go:80 +0x39 fp=0xc268350a40 sp=0xc268350a28
...additional frames elided...
created by net/http.(*Server).Serve
    /usr/local/go/src/pkg/net/http/server.go:1721 +0x313

goroutine 16 [IO wait]:
net.runtime_pollWait(0x6609a8, 0x72, 0x0)
    /private/var/folders/00/0sdwh000h01000cxqpysvccm0035qk/T/makerelease910109054/go/src/pkg/runtime/netpoll.goc:146 +0x66
net.(*pollDesc).Wait(0xc20802ae60, 0x72, 0x0, 0x0)
    /usr/local/go/src/pkg/net/fd_poll_runtime.go:84 +0x46
net.(*pollDesc).WaitRead(0xc20802ae60, 0x0, 0x0)
    /usr/local/go/src/pkg/net/fd_poll_runtime.go:89 +0x42
net.(*netFD).accept(0xc20802ae00, 0x45d450, 0x0, 0x65f3f0, 0x23)
    /usr/local/go/src/pkg/net/fd_unix.go:419 +0x343
net.(*TCPListener).AcceptTCP(0xc2080300c8, 0xb95e3, 0x0, 0x0)
    /usr/local/go/src/pkg/net/tcpsock_posix.go:234 +0x5d
net/http.tcpKeepAliveListener.Accept(0xc2080300c8, 0x0, 0x0, 0x0, 0x0)
    /usr/local/go/src/pkg/net/http/server.go:1947 +0x4b
net/http.(*Server).Serve(0xc208004420, 0x660a58, 0xc2080300c8, 0x0, 0x0)
    /usr/local/go/src/pkg/net/http/server.go:1698 +0x91
net/http.(*Server).ListenAndServe(0xc208004420, 0x0, 0x0)
    /usr/local/go/src/pkg/net/http/server.go:1688 +0x14d
net/http.ListenAndServe(0xc208000dd8, 0x5, 0x65f980, 0xc208032200, 0x0, 0x0)
    /usr/local/go/src/pkg/net/http/server.go:1778 +0x79
github.com/go-martini/martini.(*Martini).RunOnAddr(0xc208032200, 0xc208000dd8, 0x5)
    /Users/dougbarrett/goapps/src/github.com/go-martini/martini/martini.go:80 +0x27c
github.com/go-martini/martini.(*Martini).Run(0xc208032200)
    /Users/dougbarrett/goapps/src/github.com/go-martini/martini/martini.go:92 +0xf1
main.main()
    /Users/dougbarrett/goapps/src/bitbucket.com/yowgo/analytics/backend/main.go:32 +0x48e

goroutine 19 [finalizer wait]:
runtime.park(0x14d60, 0x5a1cf0, 0x59ff49)
    /usr/local/go/src/pkg/runtime/proc.c:1369 +0x89
runtime.parkunlock(0x5a1cf0, 0x59ff49)
    /usr/local/go/src/pkg/runtime/proc.c:1385 +0x3b
runfinq()
    /usr/local/go/src/pkg/runtime/mgc0.c:2644 +0xcf
runtime.goexit()
    /usr/local/go/src/pkg/runtime/proc.c:1445

goroutine 25 [runnable]:
net.runtime_pollWait(0x660848, 0x72, 0x0)
    /private/var/folders/00/0sdwh000h01000cxqpysvccm0035qk/T/makerelease910109054/go/src/pkg/runtime/netpoll.goc:146 +0x66
net.(*pollDesc).Wait(0xc20802aa70, 0x72, 0x0, 0x0)
    /usr/local/go/src/pkg/net/fd_poll_runtime.go:84 +0x46
net.(*pollDesc).WaitRead(0xc20802aa70, 0x0, 0x0)
    /usr/local/go/src/pkg/net/fd_poll_runtime.go:89 +0x42
net.(*netFD).Read(0xc20802aa10, 0xc208088000, 0x1000, 0x1000, 0x0, 0x65f3f0, 0x23)
    /usr/local/go/src/pkg/net/fd_unix.go:242 +0x34c
net.(*conn).Read(0xc2080300a8, 0xc208088000, 0x1000, 0x1000, 0x0, 0x0, 0x0)
    /usr/local/go/src/pkg/net/net.go:122 +0xe7
crypto/tls.(*block).readFromUntil(0xc2080ccab0, 0x660af0, 0xc2080300a8, 0x5, 0x0, 0x0)
    /usr/local/go/src/pkg/crypto/tls/conn.go:451 +0xd9
crypto/tls.(*Conn).readRecord(0xc208064840, 0x17, 0x0, 0x0)
    /usr/local/go/src/pkg/crypto/tls/conn.go:536 +0x1ff
crypto/tls.(*Conn).Read(0xc208064840, 0xc208089000, 0x1000, 0x1000, 0x0, 0x0, 0x0)
    /usr/local/go/src/pkg/crypto/tls/conn.go:901 +0x16a
net/http.noteEOFReader.Read(0x66a0f0, 0xc208064840, 0xc208042318, 0xc208089000, 0x1000, 0x1000, 0x5b42a0, 0x0, 0x0)
    /usr/local/go/src/pkg/net/http/transport.go:1203 +0x72
net/http.(*noteEOFReader).Read(0xc208341700, 0xc208089000, 0x1000, 0x1000, 0xc20804e290, 0x0, 0x0)
    <autogenerated>:124 +0xca
bufio.(*Reader).fill(0xc2080e0060)
    /usr/local/go/src/pkg/bufio/bufio.go:97 +0x1b3
bufio.(*Reader).Peek(0xc2080e0060, 0x1, 0x0, 0x0, 0x0, 0x0, 0x0)
    /usr/local/go/src/pkg/bufio/bufio.go:132 +0x101
net/http.(*persistConn).readLoop(0xc2080422c0)
    /usr/local/go/src/pkg/net/http/transport.go:782 +0x95
created by net/http.(*Transport).dialConn
    /usr/local/go/src/pkg/net/http/transport.go:600 +0x93f

goroutine 17 [syscall]:
runtime.goexit()
    /usr/local/go/src/pkg/runtime/proc.c:1445

goroutine 26 [select]:
net/http.(*persistConn).writeLoop(0xc2080422c0)
    /usr/local/go/src/pkg/net/http/transport.go:885 +0x38f
created by net/http.(*Transport).dialConn
    /usr/local/go/src/pkg/net/http/transport.go:601 +0x957
2014/11/12 12:55:48 http: proxy error: EOF

An error http.DefaultTransport and http.DefaultClient are not available on App Engine server

Hi,
I try to connect LinkedIn on local development app engine server, but get the error when code run to
"github.com/golang/oauth2".updateToken
Is the problem caused by app engine not support http.DefaultClient but r, err := http.DefaultClient.PostForm(c.tokenURL.String(), v) in updateToken?

below is my main.go:

package main

import (
    "github.com/go-martini/martini"
    "net/http"
    gooauth2 "github.com/golang/oauth2"
    "github.com/martini-contrib/oauth2"
    "github.com/martini-contrib/sessions"
)

func init() {
    m := martini.Classic()
    m.Use(sessions.Sessions("my_session", sessions.NewCookieStore([]byte("secret_123"))))
    m.Use(oauth2.LinkedIn(&gooauth2.Options{
        ClientID:     "clientId",
        ClientSecret: "client secret",
        RedirectURL:  "http://test_auth:8080/oauth2callback",
    }))
  m.Get("/login", oauth2.LoginRequired, func(tokens oauth2.Tokens) string {
    return tokens.Access()
  })

  m.Get("/logout", func(sess sessions.Session) string {
    sess.Clear()
    return "cleared!"
  })
    http.Handle("/", m)
}

func Index(tokens oauth2.Tokens) string {
    return tokens.Access()
}

it's work if run the app by go run.

Any idea about this?
Thanks!

Getting a build error when I try and follow the example in the README

package main

import (
    "github.com/codegangsta/martini"
    "github.com/martini-contrib/oauth2"
    "github.com/martini-contrib/sessions"
)

func main() {
    m := martini.Classic()
    m.Use(sessions.Sessions("my_session", sessions.NewCookieStore([]byte("secret123"))))
    m.Use(oauth2.Google(&oauth2.Options{
        ClientId:     "client_id",
        ClientSecret: "client_secret",
        RedirectURL:  "redirect_url",
        Scopes:       []string{"https://www.googleapis.com/auth/drive"},
    }))
    // tokens are injected to the handlers
    m.Get("/access_token", func(tokens Tokens) (int, string) {
        if tokens != nil {
            return 200, tokens.AccessToken()
        }
        return 403, "not authenticated"
    })
    m.Run()
}
go build
# github.com/superlogical/oauth
./server.go:19: undefined: Tokens

Expired() call for Token panics

Hi there!

I was running martini with this library, and I got a stack overflow error whenever the oauth2callback was made from Facebook. I tracked down the error, and came to this:

// Expired returns whether the access token is expired or not.
func (t *token) Expired() bool {
    if t == nil {
        return true
    }
    return t.Expired()
}

The issue is that in commit: 478a5ec
The name was changed and now the token type in martini-oauth seems to eclipse the underlying type and calls this method recursively, and then stack overflows!

I will make a pull request later, and the fix is pretty simple:

// Expired returns whether the access token is expired or not.
func (t *token) Expired() bool {
        ...
    return t.Token.Expired()
}

Some other facts to help recreate this bug:
OS: Mac OS X
Go version used: go1.3
Code used (removing secret stuff as necessary)

func main() {
    m := martini.Classic()
    m.Use(sessions.Sessions("my_session", sessions.NewCookieStore([]byte("secret123"))))
    m.Use(oauth2.Facebook(
        goauth2.Client("client_id", "secret_api_key"),
        goauth2.RedirectURL("http://local.foo.com/oauth2callback"), //over-rode localhost for fb complaint
        goauth2.Scope("public_profile"),
    ))
    m.Get("/", func(tokens oauth2.Tokens) string {
        if tokens.Expired() {
            return "not logged in, or the access token is expired"
        }
        return "logged in"
    })
    m.Get("/restrict", oauth2.LoginRequired, func(tokens oauth2.Tokens) string {
        return tokens.Access()
    })
    m.Get("/success", oauth2.LoginRequired, func(tokens oauth2.Tokens) string {
        return tokens.Access()
    })

    log.Fatal(http.ListenAndServe(":80", m)) //test.
}

go to: local.foo.com/resctrict and it should break on the return call for oauth2callback.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.