Skip to content
Identity management in Ruby for the Tanker SDK
Ruby Shell
Branch: master
Clone or download
Fetching latest commit…
Cannot retrieve the latest commit at this time.
Permalink
Type Name Latest commit message Commit time
Failed to load latest commit information.
bin
examples/sinatra
lib
spec
.editorconfig
.gitignore
.rspec
.travis.yml
Gemfile
Gemfile.lock
README.md
Rakefile
tanker-identity.gemspec

README.md

Identity Travis

Identity generation in Ruby for the Tanker SDK.

Installation

This project depends on the rbnacl gem, which requires the libsodium cryptographic library.

Before going further, please follow instructions to install libsodium.

Then, add this line to your application's Gemfile:

gem 'tanker-identity', git: 'https://github.com/TankerHQ/identity-ruby' #, tag: 'vX.Y.Z'

Finally, execute:

$ bundle

API

Tanker::Identity.create_identity(app_id, app_secret, user_id)

Create a new Tanker identity. This identity is secret and must only be given to a user who has been authenticated by your application. This identity is used by the Tanker client SDK to open a Tanker session.

app_id
The app ID. You can access it from the Tanker dashboard.

app_secret
The app secret. A secret that you have saved right after the creation of your app on the Tanker dashboard.

user_id
The unique ID of a user in your application.

Tanker::Identity.create_provisional_identity(app_id, email)

Create a Tanker provisional identity. It allows you to share a resource with a user who does not have an account in your application yet.

app_id
The app ID. You can access it from the Tanker dashboard.

email
The email of the potential recipient of the resource.

Tanker::Identity.get_public_identity(identity)

Return the public identity from an identity. This public identity can be used by the Tanker client SDK to share encrypted resource.

identity
A secret identity.

Tanker::Identity.upgrade_user_token(app_id, user_id, user_token) # => identity

Return a Tanker identity from Tanker v1 user Token. Tanker v1 used a user token, when migrating to Tanker v2 you should use this function to migrate you used tokens to identities. This identity is secret and must only be given to a user who has been authenticated by your application. This identity is used by the Tanker client SDK to open a Tanker session.

app_id
The app ID. You can access it from the Tanker dashboard.

user_id
The unique ID of a user in your application.

user_token
The Tanker v1 user token.

Usage example

The server-side pseudo-code below demonstrates a typical flow to safely deliver identities to your users:

require 'tanker-identity'

# 1. store these configurations in a safe place
app_id = '<app-id>'
app_secret = '<app-secret>'

# 2. you will typically have methods to check user authentication
def authenticated? # check user is authenticated on the server
def current_user   # current authenticated user

# 3. you will need to add internal methods to store / load identities
def db_store_identity(user_id, identity)
def db_load_identity(user_id)

# 4. finally, add user facing functionality
def tanker_secret_identity(user_id)
  raise 'Not authenticated' unless authenticated?
  raise 'Not authorized' unless current_user.id == user_id

  identity = db_load_identity(user_id)

  if identity.nil?
    identity = Tanker::Identity.create_identity(app_id, app_secret, user_id)
    db_store_identity(user_id, identity)
  end

  identity
end

def tanker_public_identity(user_id)
  raise 'Not authenticated' unless authenticated?

  identity = db_load_identity(user_id)

  raise 'User does not exist or has no identity yet' unless identity

  Tanker::Identity.get_public_identity(identity)
end

Read more about identities in the Tanker documentation.

Check the examples folder for usage examples.

Development

After checking out the repo, run bin/setup to install dependencies. Then, run rake spec to run the tests. You can also run bin/console for an interactive prompt that will allow you to experiment.

To install this gem onto your local machine, run bundle exec rake install. To release a new version, update the version number in version.rb, and then run bundle exec rake release, which will create a git tag for the version, push git commits and tags, and push the .gem file to rubygems.org.

Contributing

Bug reports and pull requests are welcome on GitHub at https://github.com/TankerHQ/identity-ruby.

You can’t perform that action at this time.