go-httpbearer/README.md

38 lines
1.0 KiB
Markdown
Raw Normal View History

2023-09-22 09:25:02 +00:00
# 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](https://godoc.org/sourcecode.social/reiver/go-httpbearer?status.svg)](https://godoc.org/sourcecode.social/reiver/go-httpbearer)
## Example
Here is an example:
```go
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:
```go
"WW91IGFyZSBub3QgYSBkcm9wIGluIHRoZSBvY2Vhbi4gWW91IGFyZSB0aGUgZW50aXJlIG9jZWFuLCBpbiBhIGRyb3Au"
```