()
| 113 | } |
| 114 | |
| 115 | func Example_useTokenViaHTTP() { |
| 116 | |
| 117 | // Make a sample token |
| 118 | // In a real world situation, this token will have been acquired from |
| 119 | // some other API call (see Example_getTokenViaHTTP) |
| 120 | token, err := createToken("foo") |
| 121 | fatal(err) |
| 122 | |
| 123 | // Make request. See func restrictedHandler for example request processor |
| 124 | req, err := http.NewRequest("GET", fmt.Sprintf("http://localhost:%v/restricted", serverPort), nil) |
| 125 | fatal(err) |
| 126 | req.Header.Set("Authorization", fmt.Sprintf("Bearer %v", token)) |
| 127 | res, err := http.DefaultClient.Do(req) |
| 128 | fatal(err) |
| 129 | |
| 130 | // Read the response body |
| 131 | buf := new(bytes.Buffer) |
| 132 | io.Copy(buf, res.Body) |
| 133 | res.Body.Close() |
| 134 | fmt.Println(buf.String()) |
| 135 | |
| 136 | // Output: Welcome, foo |
| 137 | } |
| 138 | |
| 139 | func createToken(user string) (string, error) { |
| 140 | // create a signer for rsa 256 |
nothing calls this directly
no test coverage detected