cognito

package module
v0.0.4 Latest Latest
Warning

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

Go to latest
Published: Sep 12, 2020 License: Apache-2.0 Imports: 11 Imported by: 0

README

cognito-go build Go Report Card Coverage Status

JWT Authentication with AWS Cognito in Go + Gin Middleware

Usage

Single

import "github.com/hiepd/cognito-go"

c, _ := cognito.NewCognito("ap-southeast-2", "cognito-app", "xxx")
token, err := c.VerifyToken("abc")

Gin Middleware

import (
  "github.com/hiepd/cognito-go"
  "github.com/gin-gonic/gin"
)

c, _ := cognito.NewCognito("ap-southeast-2", "cognito-app", "xxx")
r := gin.New()
r.GET("/protected", c.Authorize(), protectedEndpoint)

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	ErrInvalidParam = errors.New("invalid param")
)

Functions

This section is empty.

Types

type Client

type Client interface {
	VerifyToken(tokenStr string) (*jwt.Token, error)
	Authorize(c *gin.Context)
}

func NewCognitoClient

func NewCognitoClient(region, usePoolId, clientId string) (Client, error)

type Cognito

type Cognito struct {
	// AWS App Client ID
	ClientId string

	// AWS Cognito Issuer
	Iss string

	// Map of JWKs from AWS Cognito
	PublicKeys PublicKeys
}

func (*Cognito) Authorize

func (cog *Cognito) Authorize(c *gin.Context)

func (*Cognito) VerifyToken

func (c *Cognito) VerifyToken(tokenStr string) (*jwt.Token, error)

type PublicKey

type PublicKey struct {
	Alg string `json:"alg"`
	E   string `json:"e"`
	Kid string `json:"kid"`
	Kty string `json:"kty"`
	N   string `json:"n"`
	Use string `json:"use"`
	PEM *rsa.PublicKey
}

type PublicKeys

type PublicKeys map[string]PublicKey

Directories

Path Synopsis
Package cognito is a generated GoMock package.
Package cognito is a generated GoMock package.

Jump to

Keyboard shortcuts

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