{"modulePath":"github.com/otto-eng/oapi-codegen","version":"v1.9.1","isLatest":true,"isStandardLibrary":false,"goos":"all","goarch":"all","docs":"# package server\n\n## Constants\n\n```go\nconst FakeAudience = \"example-users\"\n```\n\n```go\nconst FakeIssuer = \"fake-issuer\"\n```\n\n```go\nconst KeyID = `fake-key-id`\n```\n\n```go\nconst PermissionsClaim = \"perm\"\n```\n\n```go\nconst PrivateKey = `-----BEGIN EC PRIVATE KEY-----\nMHcCAQEEIN2dALnjdcZaIZg4QuA6Dw+kxiSW502kJfmBN3priIhPoAoGCCqGSM49\nAwEHoUQDQgAE4pPyvrB9ghqkT1Llk0A42lixkugFd/TBdOp6wf69O9Nndnp4+HcR\ns9SlG/8hjB2Hz42v4p3haKWv3uS1C6ahCQ==\n-----END EC PRIVATE KEY-----`\n```\nPrivateKey is an ECDSA private key which was generated with the following command:\n\n\topenssl ecparam -name prime256v1 -genkey -noout -out ecprivatekey.pem\n\nWe are using a hard coded key here in this example, but in real applications, you would never do this. Your JWT signing key must never be in your application, only the public key.\n\n## Variables\n\n```go\nvar ErrClaimsInvalid = errors.New(\"Provided claims do not match expected scopes\")\n```\n\n```go\nvar ErrInvalidAuthHeader = errors.New(\"Authorization header is malformed\")\n```\n\n```go\nvar ErrNoAuthHeader = errors.New(\"Authorization header is missing\")\n```\n\n## Functions\n\n```go\nfunc Authenticate(v JWSValidator, ctx context.Context, input *openapi3filter.AuthenticationInput) error\n```\nAuthenticate uses the specified validator to ensure a JWT is valid, then makes sure that the claims provided by the JWT match the scopes as required in the API.\n\n```go\nfunc CheckTokenClaims(expectedClaims []string, t jwt.Token) error\n```\n\n```go\nfunc CreateMiddleware(v JWSValidator) ([]echo.MiddlewareFunc, error)\n```\n\n```go\nfunc GetClaimsFromToken(t jwt.Token) ([]string, error)\n```\nGetClaimsFromToken returns a list of claims from the token. We store these as a list under the \"perms\" claim, short for permissions, to keep the token shorter.\n\n```go\nfunc GetJWSFromRequest(req *http.Request) (string, error)\n```\nGetJWSFromRequest extracts a JWS string from an Authorization: Bearer \\\u003cjws\u003e header\n\n```go\nfunc NewAuthenticator(v JWSValidator) openapi3filter.AuthenticationFunc\n```\n\n```go\nfunc NewServer() *server\n```\n\n## Types\n\n```go\ntype FakeAuthenticator struct {\n\tPrivateKey *ecdsa.PrivateKey\n\tKeySet     jwk.Set\n}\n```\n\n```go\nfunc NewFakeAuthenticator() (*FakeAuthenticator, error)\n```\nNewFakeAuthenticator creates an authenticator example which uses a hard coded ECDSA key to validate JWT's that it has signed itself.\n\n```go\nfunc (f *FakeAuthenticator) CreateJWSWithClaims(claims []string) ([]byte, error)\n```\nCreateJWSWithClaims is a helper function to create JWT's with the specified claims.\n\n```go\nfunc (f *FakeAuthenticator) SignToken(t jwt.Token) ([]byte, error)\n```\nSignToken takes a JWT and signs it with our priviate key, returning a JWS.\n\n```go\nfunc (f *FakeAuthenticator) ValidateJWS(jwsString string) (jwt.Token, error)\n```\nValidateJWS ensures that the critical JWT claims needed to ensure that we trust the JWT are present and with the correct values.\n\n```go\ntype JWSValidator interface {\n\tValidateJWS(jws string) (jwt.Token, error)\n}\n```\nJWSValidator is used to validate JWS payloads and return a JWT if they're valid\n\n","path":"github.com/otto-eng/oapi-codegen/examples/authenticated-api/echo/server","name":"server","synopsis":"","isRedistributable":true}
