{"record":{"id":"3907c1e255b1b978","repo":"micro/go-micro","slug":"errinvalidtoken-3907c1","errorCode":"ErrInvalidToken","errorMessage":"invalid token provided","messagePattern":"invalid token provided","errorType":"error_code","errorClass":null,"httpStatus":null,"severity":"error","filePath":"auth/jwt/token/token.go","lineNumber":16,"sourceCode":"package token\n\nimport (\n\t\"errors\"\n\t\"time\"\n\n\t\"go-micro.dev/v6/auth\"\n)\n\nvar (\n\t// ErrNotFound is returned when a token cannot be found.\n\tErrNotFound = errors.New(\"token not found\")\n\t// ErrEncodingToken is returned when the service encounters an error during encoding.\n\tErrEncodingToken = errors.New(\"error encoding the token\")\n\t// ErrInvalidToken is returned when the token provided is not valid.\n\tErrInvalidToken = errors.New(\"invalid token provided\")\n)\n\n// Provider generates and inspects tokens.\ntype Provider interface {\n\tGenerate(account *auth.Account, opts ...GenerateOption) (*Token, error)\n\tInspect(token string) (*auth.Account, error)\n\tString() string\n}\n\ntype Token struct {\n\t// The actual token\n\tToken string `json:\"token\"`\n\t// Time of token creation\n\tCreated time.Time `json:\"created\"`\n\t// Time of token expiry\n\tExpiry time.Time `json:\"expiry\"`\n}\n","sourceCodeStart":1,"sourceCodeEnd":34,"githubUrl":"https://github.com/micro/go-micro/blob/24529f140421a11a33b6999ab7944f2021cfd69c/auth/jwt/token/token.go#L1-L34","documentation":"ErrInvalidToken (message \"invalid token provided\") is returned by Provider.Inspect (and helpers such as TokenFromMetadata) in auth/jwt/token when the supplied token string cannot be parsed or verified as a valid JWT. The token may be malformed, tampered with, signed by an unknown key, or expired.","triggerScenarios":"Inspect(token) is called with a malformed, empty, wrongly-signed, or expired JWT; TokenFromMetadata extracts the Authorization header value and Inspect rejects it; a client sends a token issued by a different namespace/issuer.","commonSituations":"Expired access tokens not refreshed before reuse; copying tokens between environments with different signing keys; stripping or renaming the Authorization metadata key so the wrong value is inspected; clock skew between services causing premature expiry.","solutions":["Refresh the token via Provider.Generate / auth.Token when it is expired (check Token.Expired()) before re-sending","Confirm the client and server share the same signing key/public key and namespace configuration","Ensure the Authorization header uses the Bearer scheme and the raw JWT is passed to Inspect intact","Re-authenticate to obtain a fresh token if the old one is unrecoverable"],"exampleFix":"// before: reusing a possibly expired token blindly\nacc, err := provider.Inspect(storedToken.AccessToken)\n// after: refresh first when expired\nif storedToken.Expired() {\n    storedToken, err = provider.Generate(account)\n    if err != nil { return err }\n}\nacc, err := provider.Inspect(storedToken.AccessToken)","handlingStrategy":"try-catch","validationCode":"// basic pre-checks before sending a token\nfunc tokenUsable(tok *token.Token) bool {\n    return tok != nil && tok.AccessToken != \"\" && !tok.Expired()\n}\nif !tokenUsable(storedToken) { storedToken = refreshTokenOrReauth() }","typeGuard":"func isInvalidToken(err error) bool {\n    return errors.Is(err, token.ErrInvalidToken)\n}","tryCatchPattern":"acc, err := provider.Inspect(rawToken)\nif err != nil {\n    if errors.Is(err, token.ErrInvalidToken) {\n        // trigger re-auth / token refresh flow, return 401 to client\n        return reauthenticate()\n    }\n    return err\n}","preventionTips":["Refresh tokens proactively (check Token.Expired() before each call)","Share signing keys/namespace config consistently across services","Never strip or rewrite the Authorization metadata before inspection"],"tags":["jwt","auth","token-validation"],"backgroundTag":"jwt-token-invalid","analyzedSha":"24529f140421a11a33b6999ab7944f2021cfd69c","analyzedAt":"2026-09-01T02:52:24.923Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-08T05:18:18.240Z"}