Skip to content

Latest commit

 

History

History
 
 

gorilla-example

Folders and files

NameName
Last commit message
Last commit date

parent directory

..
 
 
 
 
 
 

Go OpenId - Gorilla Example

godoc license

This fully working example implements an HTTP server using openid Authentication middlewares and Gorilla Context to preserve the user information across the service application stack.

The AuthenticateUser middleware exported by the package openid2go/openid forwards the user information to a handler that implements the interface openid.UserHandler:

func AuthenticateUser(conf *Configuration, h UserHandler) http.Handler
type UserHandler interface {
	ServeHTTPWithUser(*User, http.ResponseWriter, *http.Request)
}

This example demonstrates how to create an adapter that implements that interface and use it to store the openid.User into a Gorilla Context. The user information can then be retrieved from the context in another point of the application stack.

Test

Download and build:

go get github.com/emanoelxavier/openid2go/gorilla-example
go build github.com/emanoelxavier/openid2go/gorilla-example

Run:

github.com\emanoelxavier\openid2go\alice-example\gorilla-example.exe

Once running you can send requests like the ones below:

GET http://localhost:5100
GET http://localhost:5100/me
Authorization: Bearer eyJhbGciOiJS...
GET http://localhost:5100/authn
Authorization: Bearer eyJhbGciOiJS...

The abbreviated token above must be replaced with the IDToken acquired from the Google OAuth PlayGround entering "openid" (without quotes) within the scope field.