omniauth-blockstack 0.0.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +7 -0
- data/.gitignore +50 -0
- data/Gemfile +5 -0
- data/Gemfile.lock +103 -0
- data/Guardfile +8 -0
- data/LICENSE +22 -0
- data/README.md +40 -0
- data/Rakefile +6 -0
- data/lib/omniauth/blockstack.rb +2 -0
- data/lib/omniauth/blockstack/version.rb +5 -0
- data/lib/omniauth/strategies/auth-request.js +2 -0
- data/lib/omniauth/strategies/blockstack.js +48301 -0
- data/lib/omniauth/strategies/blockstack.rb +79 -0
- data/omniauth-blockstack.gemspec +30 -0
- data/spec/lib/omniauth/strategies/omniauth_spec.rb +36 -0
- data/spec/spec_helper.rb +24 -0
- metadata +173 -0
| @@ -0,0 +1,79 @@ | |
| 1 | 
            +
            require 'omniauth'
         | 
| 2 | 
            +
            require 'blockstack'
         | 
| 3 | 
            +
             | 
| 4 | 
            +
            module OmniAuth
         | 
| 5 | 
            +
              module Strategies
         | 
| 6 | 
            +
                class Blockstack
         | 
| 7 | 
            +
                  class ClaimInvalid < StandardError; end
         | 
| 8 | 
            +
             | 
| 9 | 
            +
                  include OmniAuth::Strategy
         | 
| 10 | 
            +
             | 
| 11 | 
            +
                  args [:app_name, :blockstack_api]
         | 
| 12 | 
            +
             | 
| 13 | 
            +
                  option :uid_claim, 'iss'
         | 
| 14 | 
            +
                  option :info_map, {"name" => "username"}
         | 
| 15 | 
            +
                  option :leeway, nil
         | 
| 16 | 
            +
                  option :valid_within, nil
         | 
| 17 | 
            +
                  option :blockstack_api, nil
         | 
| 18 | 
            +
                  option :app_name, nil
         | 
| 19 | 
            +
                  option :app_description, ""
         | 
| 20 | 
            +
                  option :app_icons, [{}]
         | 
| 21 | 
            +
             | 
| 22 | 
            +
                  def decoded_token
         | 
| 23 | 
            +
                    @decoded_token
         | 
| 24 | 
            +
                  end
         | 
| 25 | 
            +
             | 
| 26 | 
            +
                  def request_phase
         | 
| 27 | 
            +
                    blockstack_js = File.open(File.join(File.dirname(__FILE__), "blockstack.js"), "rb").read
         | 
| 28 | 
            +
             | 
| 29 | 
            +
                    auth_request_js = File.open(File.join(File.dirname(__FILE__), "auth-request.js"), "rb").read
         | 
| 30 | 
            +
             | 
| 31 | 
            +
                    header_info = "<script>#{blockstack_js}</script>"
         | 
| 32 | 
            +
                    app_data_js = <<~JAVASCRIPT
         | 
| 33 | 
            +
                    var signingKey = null
         | 
| 34 | 
            +
                    var appManifest = {
         | 
| 35 | 
            +
                    name: "#{options.app_name}",
         | 
| 36 | 
            +
                    start_url: "#{callback_url}",
         | 
| 37 | 
            +
                    description: "#{options.app_description}",
         | 
| 38 | 
            +
                    icons: #{options.app_icons.to_json}
         | 
| 39 | 
            +
                    }
         | 
| 40 | 
            +
                    JAVASCRIPT
         | 
| 41 | 
            +
             | 
| 42 | 
            +
                    header_info << "<script>#{app_data_js}</script>"
         | 
| 43 | 
            +
                    header_info << "<script>#{auth_request_js}</script>"
         | 
| 44 | 
            +
                    form = OmniAuth::Form.new(:title => "Blockstack Auth Request Generator",
         | 
| 45 | 
            +
                    :header_info => header_info,
         | 
| 46 | 
            +
                    :url => callback_path)
         | 
| 47 | 
            +
                    form.to_response
         | 
| 48 | 
            +
                  end
         | 
| 49 | 
            +
             | 
| 50 | 
            +
                  def callback_phase
         | 
| 51 | 
            +
                    auth_response = request.params['authResponse']
         | 
| 52 | 
            +
             | 
| 53 | 
            +
                    ::Blockstack.api = options.api
         | 
| 54 | 
            +
                    ::Blockstack.leeway = options.leeway
         | 
| 55 | 
            +
                    ::Blockstack.valid_within = options.valid_within
         | 
| 56 | 
            +
                    @decoded_token = ::Blockstack.verify_auth_response auth_response
         | 
| 57 | 
            +
                    puts "decoded_token: #{decoded_token}"
         | 
| 58 | 
            +
                    super
         | 
| 59 | 
            +
             | 
| 60 | 
            +
                  rescue ::Blockstack::InvalidAuthResponse => error
         | 
| 61 | 
            +
                    fail! :invalid_auth_response, error
         | 
| 62 | 
            +
                  end
         | 
| 63 | 
            +
             | 
| 64 | 
            +
                  uid{ decoded_token[options.uid_claim] }
         | 
| 65 | 
            +
             | 
| 66 | 
            +
                  extra do
         | 
| 67 | 
            +
                    {:raw_info => decoded_token}
         | 
| 68 | 
            +
                  end
         | 
| 69 | 
            +
             | 
| 70 | 
            +
                  info do
         | 
| 71 | 
            +
                    options.info_map.inject({}) do |h,(k,v)|
         | 
| 72 | 
            +
                      h[k.to_s] = decoded_token[v.to_s]
         | 
| 73 | 
            +
                      h
         | 
| 74 | 
            +
                    end
         | 
| 75 | 
            +
                  end
         | 
| 76 | 
            +
             | 
| 77 | 
            +
                end
         | 
| 78 | 
            +
              end
         | 
| 79 | 
            +
            end
         | 
| @@ -0,0 +1,30 @@ | |
| 1 | 
            +
            # coding: utf-8
         | 
| 2 | 
            +
            lib = File.expand_path('../lib', __FILE__)
         | 
| 3 | 
            +
            $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
         | 
| 4 | 
            +
            require 'omniauth/blockstack/version'
         | 
| 5 | 
            +
             | 
| 6 | 
            +
            Gem::Specification.new do |spec|
         | 
| 7 | 
            +
              spec.name          = "omniauth-blockstack"
         | 
| 8 | 
            +
              spec.version       = Omniauth::Blockstack::VERSION
         | 
| 9 | 
            +
              spec.authors       = ["Larry Salibra"]
         | 
| 10 | 
            +
              spec.email         = ["rubygems@larrysalibra.com"]
         | 
| 11 | 
            +
              spec.description   = %q{An OmniAuth strategy to accept Blockstack Auth decentralized sign-on.}
         | 
| 12 | 
            +
              spec.summary       = %q{An OmniAuth strategy to accept Blockstack Auth decentralized sign-on.}
         | 
| 13 | 
            +
              spec.homepage      = "http://github.com/larrysalibra/omniauth-blockstack"
         | 
| 14 | 
            +
              spec.license       = "MIT"
         | 
| 15 | 
            +
             | 
| 16 | 
            +
              spec.files         = `git ls-files`.split($/)
         | 
| 17 | 
            +
              spec.executables   = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
         | 
| 18 | 
            +
              spec.test_files    = spec.files.grep(%r{^(test|spec|features)/})
         | 
| 19 | 
            +
              spec.require_paths = ["lib"]
         | 
| 20 | 
            +
             | 
| 21 | 
            +
              spec.add_development_dependency "bundler", "~> 1.3"
         | 
| 22 | 
            +
              spec.add_development_dependency "rake"
         | 
| 23 | 
            +
              spec.add_development_dependency "rspec"
         | 
| 24 | 
            +
              spec.add_development_dependency "guard"
         | 
| 25 | 
            +
              spec.add_development_dependency "guard-rspec"
         | 
| 26 | 
            +
              spec.add_development_dependency "rack-test"
         | 
| 27 | 
            +
             | 
| 28 | 
            +
              spec.add_dependency "blockstack"
         | 
| 29 | 
            +
              spec.add_dependency "omniauth", "~> 1.1"
         | 
| 30 | 
            +
            end
         | 
| @@ -0,0 +1,36 @@ | |
| 1 | 
            +
            require 'spec_helper'
         | 
| 2 | 
            +
             | 
| 3 | 
            +
            describe OmniAuth::Strategies::Blockstack do
         | 
| 4 | 
            +
              let(:response_json){ MultiJson.load(last_response.body) }
         | 
| 5 | 
            +
              let(:args){ [{}] }
         | 
| 6 | 
            +
             | 
| 7 | 
            +
              let(:app){
         | 
| 8 | 
            +
                the_args = args
         | 
| 9 | 
            +
                Rack::Builder.new do |b|
         | 
| 10 | 
            +
                  b.use Rack::Session::Cookie, secret: 'shushdonttell'
         | 
| 11 | 
            +
                  b.use OmniAuth::Strategies::Blockstack, *the_args
         | 
| 12 | 
            +
                  b.run lambda{|env| [200, {}, [(env['omniauth.auth'] || {}).to_json]]}
         | 
| 13 | 
            +
                end
         | 
| 14 | 
            +
              }
         | 
| 15 | 
            +
             | 
| 16 | 
            +
              context 'request phase' do
         | 
| 17 | 
            +
                it 'should generate a valid Blockstack auth request' do
         | 
| 18 | 
            +
                  # TODO write this test
         | 
| 19 | 
            +
                  fail :not_implemented
         | 
| 20 | 
            +
                end
         | 
| 21 | 
            +
                it 'should redirect to the configured portal url' do
         | 
| 22 | 
            +
                  get '/auth/blockstack'
         | 
| 23 | 
            +
                  expect(last_response.status).to eq(302)
         | 
| 24 | 
            +
                  # TODO finish this test
         | 
| 25 | 
            +
                  fail :not_implemented
         | 
| 26 | 
            +
                  expect(last_response.headers['Location']).to eq("http://localhost:8888/auth?authRequest=#{auth_request}")
         | 
| 27 | 
            +
                end
         | 
| 28 | 
            +
              end
         | 
| 29 | 
            +
             | 
| 30 | 
            +
              context 'callback phase' do
         | 
| 31 | 
            +
                it 'should decode the response' do
         | 
| 32 | 
            +
                  # TODO write this test
         | 
| 33 | 
            +
                  fail :not_implemented
         | 
| 34 | 
            +
                end
         | 
| 35 | 
            +
              end
         | 
| 36 | 
            +
            end
         | 
    
        data/spec/spec_helper.rb
    ADDED
    
    | @@ -0,0 +1,24 @@ | |
| 1 | 
            +
            $:.unshift File.dirname(__FILE__) + "/../lib"
         | 
| 2 | 
            +
            require 'rack/test'
         | 
| 3 | 
            +
             | 
| 4 | 
            +
            require 'omniauth/blockstack'
         | 
| 5 | 
            +
            OmniAuth.config.logger = Logger.new('/dev/null')
         | 
| 6 | 
            +
            # This file was generated by the `rspec --init` command. Conventionally, all
         | 
| 7 | 
            +
            # specs live under a `spec` directory, which RSpec adds to the `$LOAD_PATH`.
         | 
| 8 | 
            +
            # Require this file using `require "spec_helper"` to ensure that it is only
         | 
| 9 | 
            +
            # loaded once.
         | 
| 10 | 
            +
            #
         | 
| 11 | 
            +
            # See http://rubydoc.info/gems/rspec-core/RSpec/Core/Configuration
         | 
| 12 | 
            +
            RSpec.configure do |config|
         | 
| 13 | 
            +
              config.treat_symbols_as_metadata_keys_with_true_values = true
         | 
| 14 | 
            +
              config.run_all_when_everything_filtered = true
         | 
| 15 | 
            +
              config.filter_run :focus
         | 
| 16 | 
            +
             | 
| 17 | 
            +
              include Rack::Test::Methods
         | 
| 18 | 
            +
             | 
| 19 | 
            +
              # Run specs in random order to surface order dependencies. If you find an
         | 
| 20 | 
            +
              # order dependency and want to debug it, you can fix the order by providing
         | 
| 21 | 
            +
              # the seed, which is printed after each run.
         | 
| 22 | 
            +
              #     --seed 1234
         | 
| 23 | 
            +
              config.order = 'random'
         | 
| 24 | 
            +
            end
         | 
    
        metadata
    ADDED
    
    | @@ -0,0 +1,173 @@ | |
| 1 | 
            +
            --- !ruby/object:Gem::Specification
         | 
| 2 | 
            +
            name: omniauth-blockstack
         | 
| 3 | 
            +
            version: !ruby/object:Gem::Version
         | 
| 4 | 
            +
              version: 0.0.2
         | 
| 5 | 
            +
            platform: ruby
         | 
| 6 | 
            +
            authors:
         | 
| 7 | 
            +
            - Larry Salibra
         | 
| 8 | 
            +
            autorequire: 
         | 
| 9 | 
            +
            bindir: bin
         | 
| 10 | 
            +
            cert_chain: []
         | 
| 11 | 
            +
            date: 2017-03-14 00:00:00.000000000 Z
         | 
| 12 | 
            +
            dependencies:
         | 
| 13 | 
            +
            - !ruby/object:Gem::Dependency
         | 
| 14 | 
            +
              name: bundler
         | 
| 15 | 
            +
              requirement: !ruby/object:Gem::Requirement
         | 
| 16 | 
            +
                requirements:
         | 
| 17 | 
            +
                - - "~>"
         | 
| 18 | 
            +
                  - !ruby/object:Gem::Version
         | 
| 19 | 
            +
                    version: '1.3'
         | 
| 20 | 
            +
              type: :development
         | 
| 21 | 
            +
              prerelease: false
         | 
| 22 | 
            +
              version_requirements: !ruby/object:Gem::Requirement
         | 
| 23 | 
            +
                requirements:
         | 
| 24 | 
            +
                - - "~>"
         | 
| 25 | 
            +
                  - !ruby/object:Gem::Version
         | 
| 26 | 
            +
                    version: '1.3'
         | 
| 27 | 
            +
            - !ruby/object:Gem::Dependency
         | 
| 28 | 
            +
              name: rake
         | 
| 29 | 
            +
              requirement: !ruby/object:Gem::Requirement
         | 
| 30 | 
            +
                requirements:
         | 
| 31 | 
            +
                - - ">="
         | 
| 32 | 
            +
                  - !ruby/object:Gem::Version
         | 
| 33 | 
            +
                    version: '0'
         | 
| 34 | 
            +
              type: :development
         | 
| 35 | 
            +
              prerelease: false
         | 
| 36 | 
            +
              version_requirements: !ruby/object:Gem::Requirement
         | 
| 37 | 
            +
                requirements:
         | 
| 38 | 
            +
                - - ">="
         | 
| 39 | 
            +
                  - !ruby/object:Gem::Version
         | 
| 40 | 
            +
                    version: '0'
         | 
| 41 | 
            +
            - !ruby/object:Gem::Dependency
         | 
| 42 | 
            +
              name: rspec
         | 
| 43 | 
            +
              requirement: !ruby/object:Gem::Requirement
         | 
| 44 | 
            +
                requirements:
         | 
| 45 | 
            +
                - - ">="
         | 
| 46 | 
            +
                  - !ruby/object:Gem::Version
         | 
| 47 | 
            +
                    version: '0'
         | 
| 48 | 
            +
              type: :development
         | 
| 49 | 
            +
              prerelease: false
         | 
| 50 | 
            +
              version_requirements: !ruby/object:Gem::Requirement
         | 
| 51 | 
            +
                requirements:
         | 
| 52 | 
            +
                - - ">="
         | 
| 53 | 
            +
                  - !ruby/object:Gem::Version
         | 
| 54 | 
            +
                    version: '0'
         | 
| 55 | 
            +
            - !ruby/object:Gem::Dependency
         | 
| 56 | 
            +
              name: guard
         | 
| 57 | 
            +
              requirement: !ruby/object:Gem::Requirement
         | 
| 58 | 
            +
                requirements:
         | 
| 59 | 
            +
                - - ">="
         | 
| 60 | 
            +
                  - !ruby/object:Gem::Version
         | 
| 61 | 
            +
                    version: '0'
         | 
| 62 | 
            +
              type: :development
         | 
| 63 | 
            +
              prerelease: false
         | 
| 64 | 
            +
              version_requirements: !ruby/object:Gem::Requirement
         | 
| 65 | 
            +
                requirements:
         | 
| 66 | 
            +
                - - ">="
         | 
| 67 | 
            +
                  - !ruby/object:Gem::Version
         | 
| 68 | 
            +
                    version: '0'
         | 
| 69 | 
            +
            - !ruby/object:Gem::Dependency
         | 
| 70 | 
            +
              name: guard-rspec
         | 
| 71 | 
            +
              requirement: !ruby/object:Gem::Requirement
         | 
| 72 | 
            +
                requirements:
         | 
| 73 | 
            +
                - - ">="
         | 
| 74 | 
            +
                  - !ruby/object:Gem::Version
         | 
| 75 | 
            +
                    version: '0'
         | 
| 76 | 
            +
              type: :development
         | 
| 77 | 
            +
              prerelease: false
         | 
| 78 | 
            +
              version_requirements: !ruby/object:Gem::Requirement
         | 
| 79 | 
            +
                requirements:
         | 
| 80 | 
            +
                - - ">="
         | 
| 81 | 
            +
                  - !ruby/object:Gem::Version
         | 
| 82 | 
            +
                    version: '0'
         | 
| 83 | 
            +
            - !ruby/object:Gem::Dependency
         | 
| 84 | 
            +
              name: rack-test
         | 
| 85 | 
            +
              requirement: !ruby/object:Gem::Requirement
         | 
| 86 | 
            +
                requirements:
         | 
| 87 | 
            +
                - - ">="
         | 
| 88 | 
            +
                  - !ruby/object:Gem::Version
         | 
| 89 | 
            +
                    version: '0'
         | 
| 90 | 
            +
              type: :development
         | 
| 91 | 
            +
              prerelease: false
         | 
| 92 | 
            +
              version_requirements: !ruby/object:Gem::Requirement
         | 
| 93 | 
            +
                requirements:
         | 
| 94 | 
            +
                - - ">="
         | 
| 95 | 
            +
                  - !ruby/object:Gem::Version
         | 
| 96 | 
            +
                    version: '0'
         | 
| 97 | 
            +
            - !ruby/object:Gem::Dependency
         | 
| 98 | 
            +
              name: blockstack
         | 
| 99 | 
            +
              requirement: !ruby/object:Gem::Requirement
         | 
| 100 | 
            +
                requirements:
         | 
| 101 | 
            +
                - - ">="
         | 
| 102 | 
            +
                  - !ruby/object:Gem::Version
         | 
| 103 | 
            +
                    version: '0'
         | 
| 104 | 
            +
              type: :runtime
         | 
| 105 | 
            +
              prerelease: false
         | 
| 106 | 
            +
              version_requirements: !ruby/object:Gem::Requirement
         | 
| 107 | 
            +
                requirements:
         | 
| 108 | 
            +
                - - ">="
         | 
| 109 | 
            +
                  - !ruby/object:Gem::Version
         | 
| 110 | 
            +
                    version: '0'
         | 
| 111 | 
            +
            - !ruby/object:Gem::Dependency
         | 
| 112 | 
            +
              name: omniauth
         | 
| 113 | 
            +
              requirement: !ruby/object:Gem::Requirement
         | 
| 114 | 
            +
                requirements:
         | 
| 115 | 
            +
                - - "~>"
         | 
| 116 | 
            +
                  - !ruby/object:Gem::Version
         | 
| 117 | 
            +
                    version: '1.1'
         | 
| 118 | 
            +
              type: :runtime
         | 
| 119 | 
            +
              prerelease: false
         | 
| 120 | 
            +
              version_requirements: !ruby/object:Gem::Requirement
         | 
| 121 | 
            +
                requirements:
         | 
| 122 | 
            +
                - - "~>"
         | 
| 123 | 
            +
                  - !ruby/object:Gem::Version
         | 
| 124 | 
            +
                    version: '1.1'
         | 
| 125 | 
            +
            description: An OmniAuth strategy to accept Blockstack Auth decentralized sign-on.
         | 
| 126 | 
            +
            email:
         | 
| 127 | 
            +
            - rubygems@larrysalibra.com
         | 
| 128 | 
            +
            executables: []
         | 
| 129 | 
            +
            extensions: []
         | 
| 130 | 
            +
            extra_rdoc_files: []
         | 
| 131 | 
            +
            files:
         | 
| 132 | 
            +
            - ".gitignore"
         | 
| 133 | 
            +
            - Gemfile
         | 
| 134 | 
            +
            - Gemfile.lock
         | 
| 135 | 
            +
            - Guardfile
         | 
| 136 | 
            +
            - LICENSE
         | 
| 137 | 
            +
            - README.md
         | 
| 138 | 
            +
            - Rakefile
         | 
| 139 | 
            +
            - lib/omniauth/blockstack.rb
         | 
| 140 | 
            +
            - lib/omniauth/blockstack/version.rb
         | 
| 141 | 
            +
            - lib/omniauth/strategies/auth-request.js
         | 
| 142 | 
            +
            - lib/omniauth/strategies/blockstack.js
         | 
| 143 | 
            +
            - lib/omniauth/strategies/blockstack.rb
         | 
| 144 | 
            +
            - omniauth-blockstack.gemspec
         | 
| 145 | 
            +
            - spec/lib/omniauth/strategies/omniauth_spec.rb
         | 
| 146 | 
            +
            - spec/spec_helper.rb
         | 
| 147 | 
            +
            homepage: http://github.com/larrysalibra/omniauth-blockstack
         | 
| 148 | 
            +
            licenses:
         | 
| 149 | 
            +
            - MIT
         | 
| 150 | 
            +
            metadata: {}
         | 
| 151 | 
            +
            post_install_message: 
         | 
| 152 | 
            +
            rdoc_options: []
         | 
| 153 | 
            +
            require_paths:
         | 
| 154 | 
            +
            - lib
         | 
| 155 | 
            +
            required_ruby_version: !ruby/object:Gem::Requirement
         | 
| 156 | 
            +
              requirements:
         | 
| 157 | 
            +
              - - ">="
         | 
| 158 | 
            +
                - !ruby/object:Gem::Version
         | 
| 159 | 
            +
                  version: '0'
         | 
| 160 | 
            +
            required_rubygems_version: !ruby/object:Gem::Requirement
         | 
| 161 | 
            +
              requirements:
         | 
| 162 | 
            +
              - - ">="
         | 
| 163 | 
            +
                - !ruby/object:Gem::Version
         | 
| 164 | 
            +
                  version: '0'
         | 
| 165 | 
            +
            requirements: []
         | 
| 166 | 
            +
            rubyforge_project: 
         | 
| 167 | 
            +
            rubygems_version: 2.6.8
         | 
| 168 | 
            +
            signing_key: 
         | 
| 169 | 
            +
            specification_version: 4
         | 
| 170 | 
            +
            summary: An OmniAuth strategy to accept Blockstack Auth decentralized sign-on.
         | 
| 171 | 
            +
            test_files:
         | 
| 172 | 
            +
            - spec/lib/omniauth/strategies/omniauth_spec.rb
         | 
| 173 | 
            +
            - spec/spec_helper.rb
         |