identity

package
v0.0.0-...-cb210e0 Latest Latest
Warning

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

Go to latest
Published: Mar 8, 2019 License: Apache-2.0 Imports: 8 Imported by: 0

Documentation

Overview

Copyright 2017 Northern.tech AS

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.

Copyright 2017 Northern.tech AS

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.

Copyright 2017 Northern.tech AS

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

This section is empty.

Functions

func WithContext

func WithContext(ctx context.Context, identity *Identity) context.Context

WithContext adds identity to context `ctx` and returns the resulting context.

Types

type Identity

type Identity struct {
	Subject  string
	Tenant   string
	IsUser   bool
	IsDevice bool
}

func ExtractIdentity

func ExtractIdentity(token string) (Identity, error)

Generate identity information from given JWT by extracting subject and tenant claims. Note that this function does not perform any form of token signature verification.

func ExtractIdentityFromHeaders

func ExtractIdentityFromHeaders(headers http.Header) (Identity, error)

Extract identity information from HTTP Authorization header. The header is assumed to contain data in format: `Bearer <token>`

func FromContext

func FromContext(ctx context.Context) *Identity

FromContext extracts current identity from context.Context

type IdentityMiddleware

type IdentityMiddleware struct {
	// If set to true, the middleware will update context logger setting
	// 'user_id' or 'device_id' to the value of subject field, if the token
	// is not a user or a device token, the middelware will add a 'sub'
	// field to the logger
	UpdateLogger bool
}

IdentityMiddleware adds the identity extracted from JWT token to the request's context. IdentityMiddleware does not perform any form of token signature verification. If it is not possible to extract identity from header error log will be generated. IdentityMiddleware will not stop control propagating through the chain in any case. It is recommended to use IdentityMiddleware with RequestLogMiddleware and RequestLogMiddleware should be placed before IdentityMiddleware. Otherwise, log generated by IdentityMiddleware will not contain "request_id" field.

func (*IdentityMiddleware) MiddlewareFunc

func (mw *IdentityMiddleware) MiddlewareFunc(h rest.HandlerFunc) rest.HandlerFunc

MiddlewareFunc makes IdentityMiddleware implement the Middleware interface.

Directories

Path Synopsis
cmd

Jump to

Keyboard shortcuts

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