Categorygithub.com/ajipaon/authjsgo
repositorypackage
1.0.0
Repository: https://github.com/ajipaon/authjsgo.git
Documentation: pkg.go.dev

# Packages

No description provided by the author

# README

authjsgo

MIT License Go Documentation Go Report Card

This is a package that aims to decode jwt produced using authjs only for auth.js or nextauth v5

example: config my auth.js

 const option = {
    // other configuratin
    session: { strategy: 'jwt', maxAge : 120  }, // 2 minute expired
    cookies: {
        sessionToken: {
            name: `mywebsite.session-token`, //session name token
                options: {
                httpOnly: false,
                    sameSite: 'none',
                    path: '/',
                    secure: true,
            },
        }
    },
}

documentation jwt authjs

Usage: ignore expired

package main

import (
	"github.com/ajipaon/authjsgo"
	"encoding/json"
	"fmt"
)

func main() {
	token := "your token"
	secret := []byte("your secret")
	salt := []byte("mywebsite.session-token") // use session name

	payload, _ := authjsgo.DecodeJWT(token, secret, salt, true)
	
	var claims map[string]interface{}
	if err := json.Unmarshal(payload, &claims); err != nil {
		fmt.Println("Error decode json:", err)
		return
	}
	fmt.Println(claims)
}

Usage: with expired

package main

import (
	"github.com/ajipaon/authjsgo"
	"encoding/json"
	"fmt"
)

func main() {
	
	token := "your token"
	secret := []byte("your secret")
	salt := []byte("mywebsite.session-token") // use session name

	payload, _ := authjsgo.DecodeJWT(token, secret, salt)
	
	var claims map[string]interface{}
	if err := json.Unmarshal(payload, &claims); err != nil {
		fmt.Println("Error decode json:", err)
		return
	}
	fmt.Println(claims)
}

Installation

go get github.com/ajipaon/authjsgo

Author

Ajipaon