Git Product home page Git Product logo

identity-toolkit-ruby-client's Introduction

Google Identity Toolkit Ruby Client

Google Identity Toolkit (Gitkit) ruby client library is for third party sites to easily integrate with Gitkit service.

Installation

gem install identity-toolkit-ruby-client

Examples

require 'gitkit_client'

# Create a server config file or download it from Google Developer Console
# The config file contains Gitkit library config in json format
# {
#   "clientId" : "oauth2-web-client-id.apps.googleusercontent.com",
#   "serviceAccountEmail" : "[email protected]",
#   "serviceAccountPrivateKeyFile" : "path-to-service-account-private-key-file.p12",
#   "widgetUrl" : "full-url-of-gitkit-widget-on-your-site",
#   "cookieName" : "gtoken",
#   "serverKey" : "devconsole-server-key"
# }

# Create a Gitkit client
gitkit_client = GitkitLib::GitkitClient.create_from_config_file 'gitkit-server-config.json'

# Verify the Gitkit token in the incoming http request
token = request.cookies["gtoken"]
user = gitkit_client.verify_gitkit_token token

# Upload passwords
def calc_sha1(key, plain_text, salt)
  hmac = OpenSSL::HMAC.new key, 'sha1'
  hmac << plain_text
  hmac << salt
  hmac.digest
end

hash_key = 'hash-key'

user1 = GitkitLib::GitkitUser.new
user1.email = '[email protected]'
user1.user_id = '1234'
user1.salt = 'salt-1'
user1.password_hash = calc_sha1(hash_key, '1111', 'salt-1')

user2 = GitkitLib::GitkitUser.new
user2.email = '[email protected]'
user2.user_id = '5678'
user2.salt = 'salt-2'
user2.password_hash = calc_sha1(hash_key, '5555', 'salt-2')
user2.name = '56 78'

gitkit_client.upload_users 'HMAC_SHA1', hash_key, [user1, user2]

# Get user by email
user = gitkit_client.get_user_by_email('[email protected]')

# Get user by id
user = gitkit_client.get_user_by_id('5678')

# Delete a user
gitkit_client.delete_user '5678'

# Download all accounts
gitkit_client.get_all_users(2) { |account| pp account}

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.