(e *core.RequestEvent)
| 7 | ) |
| 8 | |
| 9 | func recordAuthRefresh(e *core.RequestEvent) error { |
| 10 | record := e.Auth |
| 11 | if record == nil { |
| 12 | return e.NotFoundError("Missing auth record context.", nil) |
| 13 | } |
| 14 | |
| 15 | event := new(core.RecordAuthRefreshRequestEvent) |
| 16 | event.RequestEvent = e |
| 17 | event.Collection = record.Collection() |
| 18 | event.Record = record |
| 19 | |
| 20 | return e.App.OnRecordAuthRefreshRequest().Trigger(event, func(e *core.RecordAuthRefreshRequestEvent) error { |
| 21 | token := getAuthTokenFromRequest(e.RequestEvent) |
| 22 | |
| 23 | // skip token renewal if the token's payload doesn't explicitly allow it (e.g. impersonate tokens) |
| 24 | claims, _ := security.ParseUnverifiedJWT(token) // |
| 25 | if v, ok := claims[core.TokenClaimRefreshable]; ok && cast.ToBool(v) { |
| 26 | var tokenErr error |
| 27 | token, tokenErr = e.Record.NewAuthToken() |
| 28 | if tokenErr != nil { |
| 29 | return e.InternalServerError("Failed to refresh auth token.", tokenErr) |
| 30 | } |
| 31 | } |
| 32 | |
| 33 | return recordAuthResponse(e.RequestEvent, e.Record, token, "", nil) |
| 34 | }) |
| 35 | } |
nothing calls this directly
no test coverage detected
searching dependent graphs…