session

package
v0.0.0-...-aee9b4c Latest Latest
Warning

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

Go to latest
Published: Dec 7, 2018 License: MIT Imports: 11 Imported by: 0

README

gorails/session

Build Status

Installation

With Go and git installed:

go get -u github.com/adjust/gorails/session

Usage

import "github.com/adjust/gorails/session"

// sessionCookie - raw _<your app name>_session cookie
func getRailsSessionData(sessionCookie string) (decryptedCookieData []byte, err error) {
  decryptedCookieData, err = session.DecryptSignedCookie(sessionCookie, secretKeyBase, salt, signSalt)

  return
}

const (
  secretKeyBase = "..."                      // can be found in config/initializers/secret_token.rb
  salt          = "encrypted cookie"         // default value for Rails 4 app
  signSalt      = "signed encrypted cookie"  // default value for Rails 4 app
)

After you decrypted session data you might like to deserialize it using gorails/marshal if your Rails version is less than v4.1 and you use the default serializer config.

Rails use JSON as its default serializer from v4.1, so you can deserialize the decrypted session data as a common JSON data as what test does.

Documentation

Index

Constants

This section is empty.

Variables

View Source
var ErrInvalidSignature = errors.New("session: signature not verified")

Functions

func DecryptSignedCookie

func DecryptSignedCookie(signedCookie, secretKeyBase, salt, signSalt string) (session []byte, err error)

func EncryptSignedCookie

func EncryptSignedCookie(session []byte, secretKeyBase, salt, signSalt string) (signedCookie string, err error)

EncryptSignedCookie encrypts and signs session to produce a cookie that rails can read

Types

This section is empty.

Jump to

Keyboard shortcuts

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