()
| 79 | } |
| 80 | |
| 81 | func Example_getTokenViaHTTP() { |
| 82 | // See func authHandler for an example auth handler that produces a token |
| 83 | res, err := http.PostForm(fmt.Sprintf("http://localhost:%v/authenticate", serverPort), url.Values{ |
| 84 | "user": {"test"}, |
| 85 | "pass": {"known"}, |
| 86 | }) |
| 87 | if err != nil { |
| 88 | fatal(err) |
| 89 | } |
| 90 | |
| 91 | if res.StatusCode != 200 { |
| 92 | fmt.Println("Unexpected status code", res.StatusCode) |
| 93 | } |
| 94 | |
| 95 | // Read the token out of the response body |
| 96 | buf := new(bytes.Buffer) |
| 97 | io.Copy(buf, res.Body) |
| 98 | res.Body.Close() |
| 99 | tokenString := strings.TrimSpace(buf.String()) |
| 100 | |
| 101 | // Parse the token |
| 102 | token, err := jwt.ParseWithClaims(tokenString, &CustomClaimsExample{}, func(token *jwt.Token) (interface{}, error) { |
| 103 | // since we only use the one private key to sign the tokens, |
| 104 | // we also only use its public counter part to verify |
| 105 | return verifyKey, nil |
| 106 | }) |
| 107 | fatal(err) |
| 108 | |
| 109 | claims := token.Claims.(*CustomClaimsExample) |
| 110 | fmt.Println(claims.CustomerInfo.Name) |
| 111 | |
| 112 | //Output: test |
| 113 | } |
| 114 | |
| 115 | func Example_useTokenViaHTTP() { |
| 116 |
nothing calls this directly
no test coverage detected