cognitotokenverifier

package module
v0.0.0-...-6ac4f6b Latest Latest
Warning

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

Go to latest
Published: Sep 27, 2022 License: MIT Imports: 7 Imported by: 0

README

cognito-token-verifier

Library for verifying ID tokens and getting user data from AWS Cognito User Pool.

Usage:

  1. Import library:
import ctv "github.com/DrGermanius/cognitotokenverifier"
  1. Initialize verifier:
v, err := ctv.InitVerifier(&ctv.Config{
		Region: "eu-central-1",
		PoolID: "eu-central-1_i1A111AAb",
	})
  1. Verify token:
err = v.Verify(context.Background(), "YOUR_USER_POOL_ID_TOKEN")
  1. Get user attributes:
attrs, err := v.GetUserAttributesByToken("YOUR_USER_POOL_ID_TOKEN")

Full example:

package main

import (
	"context"
	"fmt"
	"log"

	ctv "github.com/DrGermanius/cognitotokenverifier"
)

func main() {
        v, err := ctv.InitVerifier(&ctv.Config{
		Region: "eu-central-1",
		PoolID: "eu-central-1_i1A111AAb",
	})
	if err != nil {
		log.Fatalf("init verifier error: %s", err)
	}

	err = v.Verify(context.Background(), "YOUR_USER_POOL_ID_TOKEN")
	if err != nil {
		log.Fatalf("token verify error: %s", err)
	}

	attrs, err := v.GetUserAttributesByToken("YOUR_USER_POOL_ID_TOKEN")
	if err != nil {
		log.Fatalf("get user attributes error: %s", err)
	}

	fmt.Println(attrs)
}

Documentation

Index

Constants

View Source
const (
	ErrNoKidHeader   = Error("expecting JWT header to have header kid")
	ErrKidsDontMatch = Error("no matching keyIDs are fetched")
	ErrTokenExpired  = Error("token is expired")
)

Variables

This section is empty.

Functions

func InitVerifier

func InitVerifier(cfg *Config) (*verifier, error)

Types

type Config

type Config struct {
	Region string
	PoolID string
}

type Error

type Error string

Error defines string error

func (Error) Error

func (e Error) Error() string

Error returns error message

Jump to

Keyboard shortcuts

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