gorilla-example

command
v0.1.2 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Aug 21, 2022 License: MIT, MIT Imports: 4 Imported by: 0

README

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 accross 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.

Documentation

The Go Gopher

There is no documentation for this package.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL