MCPcopy Create free account
hub / github.com/kataras/iris / generateToken

Function generateToken

_examples/auth/jwt/basic/main.go:32–47  ·  view source on GitHub ↗
(ctx iris.Context)

Source from the content-addressed store, hash-verified

30}
31
32func generateToken(ctx iris.Context) {
33 claims := fooClaims{
34 Foo: "bar",
35 }
36
37 // Sign and generate compact form token.
38 token, err := jwt.Sign(jwt.HS256, signatureSharedKey, claims, jwt.MaxAge(10*time.Minute))
39 if err != nil {
40 ctx.StopWithStatus(iris.StatusInternalServerError)
41 return
42 }
43
44 tokenString := string(token) // or jwt.BytesToString
45 ctx.HTML(`Token: ` + tokenString + `<br/><br/>
46 <a href="/protected?token=` + tokenString + `">/protected?token=` + tokenString + `</a>`)
47}
48
49func protected(ctx iris.Context) {
50 // Extract the token, e.g. cookie, Authorization: Bearer $token

Callers

nothing calls this directly

Calls 4

SignMethod · 0.80
StopWithStatusMethod · 0.80
MaxAgeMethod · 0.45
HTMLMethod · 0.45

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…