go-httpbearer/README.md

1.0 KiB

go-httpbearer

Package httpbearer provides tool to deal with HTTP bearer tokens, for the Go programming language.

Online Documention

Online documentation, which includes examples, can be found at: http://godoc.org/sourcecode.social/reiver/go-httpbearer

GoDoc

Example

Here is an example:

	import "sourcecode.social/reiver/go-httpbearer"

	value := req.Header.Get("Authorization")
	
	// ...
	
	bearerToken, successful := httpbearer.Parse(value)
	if !successful {
		//@TODO: the value of the Authorization header was not a bearer token.
		return ErrNotBearerToken
	}

If the Authorization header was:

Authorization: Bearer WW91IGFyZSBub3QgYSBkcm9wIGluIHRoZSBvY2Vhbi4gWW91IGFyZSB0aGUgZW50aXJlIG9jZWFuLCBpbiBhIGRyb3Au

Then the value of bearerToken would be:

"WW91IGFyZSBub3QgYSBkcm9wIGluIHRoZSBvY2Vhbi4gWW91IGFyZSB0aGUgZW50aXJlIG9jZWFuLCBpbiBhIGRyb3Au"