Ruby SDK

Use this SDK to interact with the LaunchKey Platform API in your Ruby application.

Before you can begin using the LaunchKey API, you need an service. If you have not created a service yet, you can use our Getting Started Guide to create one.

Download Source

LaunchKey Ruby SDK

Clone Source

https://github.com/LaunchKey/launchkey-ruby.git

Before You Begin

Install the LaunchKey Ruby library by adding this to your application's Gemfile:

gem 'launchkey'

And then execute:

$ bundle

Or install yourself as:

$ gem install launchkey

If you haven't already, create an service on the new app page inside your online Dashboard to use in conjunction with this project. You'll need details from the details page for the next section.

Create a API Object

If you're using Rails, you can run the generator:

Example (Rails)

Parameters

domain:string Your domain with TLD
service_key:integer Unique 10-digit Service Key from your service details page in dashboard
secret_key:string Secret Key from your service details page in dashboard
passphrase:string Retrieve private key from private.key

Example

$ rails g launchkey:install

or if using a different framework:

# Include Ruby library
require 'launchkey'

LaunchKey.configure do |config|
    config.domain = 'http://yourdomain.tld'
    config.app_key = 1234567890
    config.secret_key = 'SECRET_KEY'
    config.keypair = File.read('path/to/rsa-keypair.pem')
    config.passphrase = 'PRIVATE_KEY_PASSPHRASE'
end

Authenticating A User

To authenticate a user, use the authorize() method with the user's LaunchKey username. If the request is successfully sent, the JSON response will include the auth_request token which you'll use to reference this launch request in subsequent calls.

Definition

LaunchKey.authorize(username)

Parameters

username:string Platform username, user push ID, or end-user identifier for the user

Example

auth_request = LaunchKey.authorize('username')

Example Response

{
    "auth_request" => "dopkpq2oqhf9ej8uuud21geh6bwi9394"
}

Determine Status Of Auth Request

Once you've sent an auth request to a user, you'll need to check the status of that request to determine whether or not the user has responded. If they have responded, the response will include the auth package containing the user's encrypted response. If they haven't responded, you'll see message: "pending response..." returned in the JSON. You should keep polling until an auth package is returned. Auth requests remain valid for 5 minutes.

Definition

LaunchKey.poll_request(auth_request)

Parameters

auth_request:string The request-specific token

Example

auth_response = LaunchKey.poll_request(auth_request)

Example Response

{
    "auth" => "R8p0TXubA+R4GlOXZlyIe5R+kG+6xPDMp43Y8vaIg4+3D1ZmANXYAMssM1apBo4\/1lWDaPyUYNJopgjnY2WK\/tjkeqgkvvtnSscYGY7\/W8VYjPfv3xA2ddr9YxfS0fQtxDUAyjnn+lbd7d8uziKpTcIx5DPZ1mJ1+d0UBmPbMUf4X8WO5c3sorX"
    "user_hash" => "HO38LVDKogEn4jzIOBgjOsXlDCoTDxUvmbEQDL2SAFh"
}

Decrypt & Check Response

When the user responds, decrypt the auth package using the authorized?() method. If authorized by the user, the boolean response will be true whereas a blocked or denied request will return boolean false.

Note

If the boolean response is true, you should continue authenticating the user in your application or consider them logged in.

Definition

LaunchKey.authorized?(auth)

Parameters

auth:string Encrypted auth response from poll request

Example

LaunchKey.authorized?(auth_response['auth'])

Example Decrypted Response

{
    "device_id" => "95f5",
    "response" => "true",
    "auth_request" => "uew83ququ1xam6bjr1xvclvef79x6zgn",
    "app_pins" => "4550,3212,7723,8488,7701"
}

When A User Logs Out

If a user logs out from within your website or app, you should inform our API so we can take your service profile out of the user's Authorization List.

Definition

LaunchKey.deauthorize(auth_request)

Parameters

auth_request:string Request-specific token

Example

LaunchKey.deauthorize(auth_request)

Decrypted Response

Boolean: true

Definition

LaunchKey.create_whitelabel_user(identifier)

Parameters

identifier:string Permanent and unique identifier of this user within your service. This identifier will be used authenticate the user as well as link devices to the user's account within your directory.

Example

LaunchKey.create_whitelabel_user(identifier)

Response

The response will be a hash containing qrcode, a URL to a QR Code that will be used to link a device automatically, and code, a code to link a device manually.

Example Response

{
    "qrcode" => "https://dashboard.launchkey.com/qrcode/4uzggpm",
    "code" => "4uzggpm"
}

User Contributed

LaunchKey links to user contributed code as a resource to its community. LaunchKey does not in any way guarantee or warrant the quality and security of these code bases. User contributed code is supported by the creators. If you do find a link from the site to user contributed code that is malicious or inappropriate in any way, please report that link to LaunchKey immediately and we will investigate the claim. Submit any issue to LaunchKey support at https://launchkey.com./support. ×