auth

package
v0.0.0-...-165278f Latest Latest
Warning

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

Go to latest
Published: Jul 30, 2020 License: Apache-2.0 Imports: 6 Imported by: 0

Documentation

Overview

Copyright 2018 Portworx

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.

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.

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

View Source
const (
	// SecondDef is the abbrevation for seconds
	SecondDef = "s"
	// MinuteDef is the abbrevation for minutes
	MinuteDef = "m"
	// HourDef is the abbrevation for hours
	HourDef = "h"
	// DayDef is the abbrevation for days
	DayDef = "d"
	// YearDef is the abbrevation for years
	YearDef = "y"

	// Day is the duration of hours in a day
	Day = time.Hour * 24
	// Year is the duration of days in a year
	Year = Day * 365
)

Variables

View Source
var (
	// SecondRegex is a regular expression for finding seconds as a duration
	SecondRegex = regexp.MustCompile("^([0-9]+)" + SecondDef + "$")
	// MinuteRegex is a regular expression for finding minutes as a duration
	MinuteRegex = regexp.MustCompile("^([0-9]+)" + MinuteDef + "$")
	// HourRegex is a regular expression for finding hours as a duration
	HourRegex = regexp.MustCompile("^([0-9]+)" + HourDef + "$")
	// DayRegex is a regular expression for finding days as a duration
	DayRegex = regexp.MustCompile("^([0-9]+)" + DayDef + "$")
	// YearRegex is a regular expression for finding years as a duration
	YearRegex = regexp.MustCompile("^([0-9]+)" + YearDef + "$")
)

Functions

func ParseToDuration

func ParseToDuration(s string) (time.Duration, error)

ParseToDuration takes in a "human" type duration and changes it to time.Duration. The format for a human type is <number><type>. For example: Five days: 5d; one year: 1y.

func Token

func Token(
	claims *Claims,
	signature *Signature,
	options *Options,
) (string, error)

Token returns a signed JWT containing the claims provided

Types

type Claims

type Claims struct {
	// Issuer is the token issuer. For selfsigned token do not prefix
	// with `https://`.
	Issuer string `json:"iss"`
	// Subject identifier. Unique ID of this account
	Subject string `json:"sub" yaml:"sub"`
	// Account name
	Name string `json:"name" yaml:"name"`
	// Account email
	Email string `json:"email" yaml:"email"`
	// Roles of this account
	Roles []string `json:"roles,omitempty" yaml:"roles,omitempty"`
	// (optional) Groups in which this account is part of
	Groups []string `json:"groups,omitempty" yaml:"groups,omitempty"`
}

Claims provides information about the claims in the token See https://openid.net/specs/openid-connect-core-1_0.html#IDToken for more information.

type Options

type Options struct {
	// Expiration time in Unix format as per JWT standard
	Expiration int64
	// Issuer of the claims
	Issuer string
}

Options provide any options to apply to the token

type Signature

type Signature struct {
	Type jwt.SigningMethod
	Key  interface{}
}

Signature describes the signature type using definitions from the jwt package

func NewSignatureECDSA

func NewSignatureECDSA(pem []byte) (*Signature, error)

func NewSignatureECDSAFromFile

func NewSignatureECDSAFromFile(filename string) (*Signature, error)

func NewSignatureRSA

func NewSignatureRSA(pem []byte) (*Signature, error)

func NewSignatureRSAFromFile

func NewSignatureRSAFromFile(filename string) (*Signature, error)

func NewSignatureSharedSecret

func NewSignatureSharedSecret(secret string) (*Signature, error)

Jump to

Keyboard shortcuts

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