Package **httpbearer** provides tool to deal with HTTP bearer tokens, for the Go programming language. The HTTP Bearer token is associated with OAuth, but is sometimes used outside of OAuth.
Go to file
Charles Iliya Krempeaux fa167b5757 initial commits 2023-09-22 18:25:02 +09:00
LICENSE initial commits 2023-09-22 18:25:02 +09:00
README.md initial commits 2023-09-22 18:25:02 +09:00
go.mod initial commits 2023-09-22 18:25:02 +09:00
parse.go initial commits 2023-09-22 18:25:02 +09:00
parse_test.go initial commits 2023-09-22 18:25:02 +09:00
trimleft.go initial commits 2023-09-22 18:25:02 +09:00
trimleft_test.go initial commits 2023-09-22 18:25:02 +09:00

README.md

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"