The following token store adapters are bundled together with fmrest-core.
This is the default token store. It uses a memory-based store for the session tokens. This is generally good enough during development, but generally a bad idea for production as in-memory tokens aren't shared across threads/processes.
# config/initializers/fmrest.rb
FmRest.token_store = FmRest::TokenStore::MemoryOn Rails apps that already use ActiveRecord, setting up this token store should be dead simple:
FmRest.token_store = FmRest::TokenStore::ActiveRecordNo migrations are needed, the token store table will be created automatically
when needed, defaulting to the table name "fmrest_session_tokens". If you want
to change the table name you can do so by initializing the token store and
passing it the :table_name option:
FmRest.token_store = FmRest::TokenStore::ActiveRecord.new(table_name: "my_token_store")To use the Redis token store add gem "redis" to your Gemfile, then do:
FmRest.token_store = FmRest::TokenStore::RedisYou can also initialize it with the following options:
:redis- ARedisobject to use as connection, if ommited a newRedisobject will be created with remaining options:prefix- The prefix to use for token keys, by default"fmrest-token:"- Any other options will be passed to
Redis.newif:redisisn't provided
Examples:
# Passing a Redis connection explicitly
FmRest.token_store = FmRest::TokenStore::Redis.new(redis: Redis.new, prefix: "my-fancy-prefix:")
# Passing options for Redis.new
FmRest.token_store = FmRest::TokenStore::Redis.new(prefix: "my-fancy-prefix:", host: "10.0.1.1", port: 6380, db: 15)Moneta is a key/value store wrapper around many different storage backends. If ActiveRecord or Redis don't suit your needs, chances are Moneta will.
To use it add gem "moneta" to your Gemfile, then do:
FmRest.token_store = FmRest::TokenStore::MonetaBy default the :Memory moneta backend will be used.
You can also initialize it with the following options:
:backend- The moneta backend to initialize the store with:prefix- The prefix to use for token keys, by default"fmrest-token:"- Any other options will be passed to
Moneta.new
Examples:
# Using YAML as a backend with a custom prefix
FmRest.token_store = FmRest::TokenStore::Moneta.new(
backend: :YAML,
file: "tmp/tokens.yml",
prefix: "my-tokens"
)