| 
									
										
										
										
											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. | 
					
						
							| 
									
										
										
										
											2023-09-22 09:27:07 +00:00
										 |  |  | The HTTP Bearer token is associated with OAuth, but is sometimes used outside of OAuth. | 
					
						
							| 
									
										
										
										
											2023-09-22 09:25:02 +00:00
										 |  |  | 
 | 
					
						
							|  |  |  | ## Online Documention
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | Online documentation, which includes examples, can be found at: http://godoc.org/sourcecode.social/reiver/go-httpbearer | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | [](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" | 
					
						
							|  |  |  | ``` |