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

Function FromJSON

middleware/jwt/extractor.go:42–71  ·  view source on GitHub ↗

FromJSON is a token extractor. Reads a json request body and extracts the json based on the given field. The request content-type should contain the: application/json header value, otherwise this method will not try to read and consume the body.

(jsonKey string)

Source from the content-addressed store, hash-verified

40// The request content-type should contain the: application/json header value, otherwise
41// this method will not try to read and consume the body.
42func FromJSON(jsonKey string) TokenExtractor {
43 return func(ctx *context.Context) string {
44 if ctx.GetContentTypeRequested() != context.ContentJSONHeaderValue {
45 return ""
46 }
47
48 var m context.Map
49 ctx.RecordRequestBody(true)
50 defer ctx.RecordRequestBody(false)
51 if err := ctx.ReadJSON(&m); err != nil {
52 return ""
53 }
54
55 if m == nil {
56 return ""
57 }
58
59 v, ok := m[jsonKey]
60 if !ok {
61 return ""
62 }
63
64 tok, ok := v.(string)
65 if !ok {
66 return ""
67 }
68
69 return tok
70 }
71}

Callers

nothing calls this directly

Calls 3

RecordRequestBodyMethod · 0.80
ReadJSONMethod · 0.45

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…