rails_compat

package module
v0.0.0-...-db6d955 Latest Latest
Warning

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

Go to latest
Published: Jun 8, 2024 License: MIT Imports: 10 Imported by: 0

README

Rails Compat Mode

This is is a simple Go package that enables you to read Rails cookies set by Devise and Warden in Go.

Why do you need it?

When you want to port over a rails app to a go codebase but you still want to access the user id from Go, then you use this package to get the user key.

Usage

// keyBase is from environment variable SECRET_KEY_BASE
var sess = map[string]interface{}
decrypted = rails_compat.DecodeRailsSession(cookie, keyBase)
buffer := bytes.NewBuffer([]byte(decrypted))
decoder = json.NewDecoder(buffer)
err := decoder.Decode(&sess)

// The user id is present in the `warden.user.user.key` as the first item of the first item in the array
// I have a utility method to extract it.
uid, err = rails_compat.ExtractUserId(decrypted)

Documentation

Index

Constants

View Source
const WARDEN_FORMAT_ERROR = "warden user key format invalid"

Variables

This section is empty.

Functions

func DecodeRailsSession

func DecodeRailsSession(cookie, keyBase string) string

DecodeRailsSession takes a rails cookie, and the secret_key_base from your secrets.yml and decrypts the session as a string

func ExtractUserId

func ExtractUserId(jsonString string) (int, error)

ExtractUserId extracts User Id from the decrypted cookie Please note that it assumes that the model name is user

Types

This section is empty.

Jump to

Keyboard shortcuts

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