├── Rakefile ├── lib └── omniauth │ ├── accountkit.rb │ ├── accountkit │ └── version.rb │ └── strategies │ └── accountkit.rb ├── .gitignore ├── bin ├── setup └── console ├── Gemfile ├── CHANGELOG.md ├── README.md ├── omniauth-accountkit.gemspec └── LICENSE.txt /Rakefile: -------------------------------------------------------------------------------- 1 | require "bundler/gem_tasks" 2 | task :default => :spec 3 | -------------------------------------------------------------------------------- /lib/omniauth/accountkit.rb: -------------------------------------------------------------------------------- 1 | require "omniauth/accountkit/version" 2 | require "omniauth/strategies/accountkit" 3 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | /.bundle/ 2 | /.yardoc 3 | /_yardoc/ 4 | /coverage/ 5 | /doc/ 6 | /pkg/ 7 | /spec/reports/ 8 | /tmp/ 9 | -------------------------------------------------------------------------------- /lib/omniauth/accountkit/version.rb: -------------------------------------------------------------------------------- 1 | module Omniauth 2 | module Accountkit 3 | VERSION = "0.1.0" 4 | end 5 | end 6 | -------------------------------------------------------------------------------- /bin/setup: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env bash 2 | set -euo pipefail 3 | IFS=$'\n\t' 4 | set -vx 5 | 6 | bundle install 7 | 8 | # Do any other automated setup that you need to do here 9 | -------------------------------------------------------------------------------- /Gemfile: -------------------------------------------------------------------------------- 1 | source "https://rubygems.org" 2 | 3 | git_source(:github) {|repo_name| "https://github.com/#{repo_name}" } 4 | 5 | # Specify your gem's dependencies in omniauth-accountkit.gemspec 6 | gemspec 7 | -------------------------------------------------------------------------------- /bin/console: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env ruby 2 | 3 | require "bundler/setup" 4 | require "omniauth/accountkit" 5 | 6 | # You can add fixtures and/or initialization code here to make experimenting 7 | # with your gem easier. You can also use a different console, if you like. 8 | 9 | # (If you use this, don't forget to add pry to your Gemfile!) 10 | # require "pry" 11 | # Pry.start 12 | 13 | require "irb" 14 | IRB.start(__FILE__) 15 | -------------------------------------------------------------------------------- /CHANGELOG.md: -------------------------------------------------------------------------------- 1 | # Changelog 2 | All notable changes to this project will be documented in this file. 3 | 4 | The format is based on [Keep a Changelog](http://keepachangelog.com/en/1.0.0/) 5 | and this project adheres to [Semantic Versioning](http://semver.org/spec/v2.0.0.html). 6 | 7 | ## [Unreleased] 8 | 9 | ## 0.1.0 - 2018-05-28 10 | ### Added 11 | 12 | * Import the project with initial implementation. 13 | 14 | [Unreleased]: https://github.com/polydice/omniauth-accountkit/compare/v0.1.0...HEAD -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # OmniAuth AccountKit 2 | 3 | Account Kit strategy for OmniAuth. 4 | 5 | ## Installation 6 | 7 | Add this line to your application's Gemfile: 8 | 9 | ```ruby 10 | gem 'omniauth-accountkit' 11 | ``` 12 | 13 | Then `bundle install` 14 | 15 | ## Usage 16 | 17 | Read the OmniAuth docs for detailed instructions: https://github.com/intridea/omniauth. 18 | 19 | Here's an example: 20 | 21 | ```ruby 22 | Rails.application.config.middleware.use OmniAuth::Builder do 23 | provider :accountkit, ENV["ACCOUNTKIT_APP_ID"], ENV["ACCOUNTKIT_APP_SECRET"] 24 | end 25 | ``` 26 | 27 | ## Contributing 28 | 29 | Bug reports and pull requests are welcome on GitHub at https://github.com/polydice/omniauth-accountkit. 30 | 31 | ## License 32 | 33 | The gem is available as open source under the terms of the [MIT License](https://opensource.org/licenses/MIT). 34 | -------------------------------------------------------------------------------- /omniauth-accountkit.gemspec: -------------------------------------------------------------------------------- 1 | 2 | lib = File.expand_path("../lib", __FILE__) 3 | $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib) 4 | require "omniauth/accountkit/version" 5 | 6 | Gem::Specification.new do |spec| 7 | spec.name = "omniauth-accountkit" 8 | spec.version = Omniauth::Accountkit::VERSION 9 | spec.authors = ["Richard Lee"] 10 | spec.email = ["rl@polydice.com"] 11 | 12 | spec.summary = %q{OmniAuth strategy for AccountKit} 13 | spec.description = spec.summary 14 | spec.homepage = "https://github.com/polydice/omniauth-accountkit" 15 | spec.license = "MIT" 16 | 17 | spec.files = `git ls-files -z`.split("\x0").reject do |f| 18 | f.match(%r{^(test|spec|features)/}) 19 | end 20 | spec.bindir = "exe" 21 | spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) } 22 | spec.require_paths = ["lib"] 23 | 24 | spec.add_runtime_dependency 'omniauth-oauth2', '>= 1.4.0', '< 2.0' 25 | 26 | spec.add_development_dependency "bundler", "~> 1.16" 27 | spec.add_development_dependency "rake", "~> 10.0" 28 | end 29 | -------------------------------------------------------------------------------- /LICENSE.txt: -------------------------------------------------------------------------------- 1 | The MIT License (MIT) 2 | 3 | Copyright (c) 2018 Richard Lee 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy 6 | of this software and associated documentation files (the "Software"), to deal 7 | in the Software without restriction, including without limitation the rights 8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | copies of the Software, and to permit persons to whom the Software is 10 | furnished to do so, subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in 13 | all copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 21 | THE SOFTWARE. 22 | -------------------------------------------------------------------------------- /lib/omniauth/strategies/accountkit.rb: -------------------------------------------------------------------------------- 1 | require 'omniauth-oauth2' 2 | 3 | module OmniAuth 4 | module Strategies 5 | class AccountKit < OmniAuth::Strategies::OAuth2 6 | option :client_options, { 7 | site: "https://graph.accountkit.com/v1.2/", 8 | authorize_url: "https://www.accountkit.com/v1.2/basic/dialog/sms_login/", 9 | token_url: "access_token", 10 | token_method: :get 11 | } 12 | 13 | option :provider_ignores_state, true 14 | 15 | def request_phase 16 | redirect client.auth_code.authorize_url({app_id: options.client_id, redirect: callback_url}.merge(authorize_params)) 17 | end 18 | 19 | def authorize_params 20 | super.tap do |params| 21 | params["fbAppEventsEnabled"] = true 22 | end 23 | end 24 | 25 | def token_params 26 | super.tap do |params| 27 | params["access_token"] = app_access_token 28 | end 29 | end 30 | 31 | uid { raw_info['id'] } 32 | 33 | info do 34 | { 35 | number: raw_info['phone']['number'], 36 | country_prefix: raw_info['phone']['country_prefix'], 37 | national_number: raw_info['phone']['national_number'] 38 | } 39 | end 40 | 41 | extra do 42 | { 43 | raw_info: raw_info 44 | } 45 | end 46 | 47 | def raw_info 48 | @raw_info ||= access_token.get('/me').parsed 49 | end 50 | 51 | protected 52 | 53 | def build_access_token 54 | verifier = request.params["code"] 55 | client.auth_code.get_token(verifier, token_params.to_hash(symbolize_keys: true), deep_symbolize(options.auth_token_params)) 56 | end 57 | 58 | private 59 | 60 | def app_access_token 61 | "AA|#{options.client_id}|#{options.client_secret}" 62 | end 63 | end 64 | end 65 | end 66 | 67 | OmniAuth.config.add_camelization 'accountkit', 'AccountKit' 68 | --------------------------------------------------------------------------------