auth

package
v0.0.0-...-e54eb34 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Sep 22, 2025 License: Apache-2.0 Imports: 9 Imported by: 0

Documentation

Overview

Copyright Axis Communications AB.

For a full list of individual contributors, please see the commit history.

Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at

http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License.

Index

Constants

This section is empty.

Variables

View Source
var (
	ErrTokenInvalid = errors.New("invalid token")
	ErrTokenExpired = jwt.ErrTokenExpired
)

Functions

This section is empty.

Types

type Authorizer

type Authorizer struct {
	// contains filtered or unexported fields
}

func NewAuthorizer

func NewAuthorizer(pub, priv []byte) (*Authorizer, error)

NewAuthorizer loads private and public pem keys and creates a new authorizer. The private key can be set to an empty []byte but it would only be possible to verify tokens and not create new ones.

func (Authorizer) Middleware

func (a Authorizer) Middleware(
	permittedScope scope.Var,
	fn func(http.ResponseWriter, *http.Request, httprouter.Params),
) func(http.ResponseWriter, *http.Request, httprouter.Params)

Middleware implements an httprouter middleware to use for verifying authorization header JWTs. Scope is added to the context of the request and can be accessed by

s := r.Context().Value("scope")
tokenScope, ok := s.(scope.Scope)

func (Authorizer) NewToken

func (a Authorizer) NewToken(identifier string, tokenScope scope.Scope, expire time.Time) (string, error)

NewToken generates a new JWT for an identifier.

func (Authorizer) VerifyToken

func (a Authorizer) VerifyToken(tokenString string) (*jwt.Token, error)

VerifyToken verifies that a token is properly signed with a specific signing key and has not expired.

Directories

Path Synopsis

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL