omnipass 0.0.1

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.
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: a862dc616d4d47b27c18846579f15ed2824216cc
4
+ data.tar.gz: 7f352c46146643dd14e99a4af14fa6a17c38d26d
5
+ SHA512:
6
+ metadata.gz: 986162106b093e3a8ee125c694729b2f7ad2535ffb50ac5d5ee2b88370bfc688f2f207196cb72047785e89044f84d8cb4e187fad1fd70d54236e8be2504a7ecf
7
+ data.tar.gz: 6047b4b26f05c8999096de9f95459365440de0621d74b8e32ecfc0171492b9a2c9a94a042518e281668fc1c7ef8433257f5b5a1d96e1c63f8582fc4eca495843
@@ -0,0 +1,9 @@
1
+ /.bundle/
2
+ /.yardoc
3
+ /Gemfile.lock
4
+ /_yardoc/
5
+ /coverage/
6
+ /doc/
7
+ /pkg/
8
+ /spec/reports/
9
+ /tmp/
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source 'https://rubygems.org'
2
+
3
+ # Specify your gem's dependencies in omnipass.gemspec
4
+ gemspec
@@ -0,0 +1,21 @@
1
+ The MIT License (MIT)
2
+
3
+ Copyright (c) 2016 Charles Sistovaris
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.
@@ -0,0 +1,41 @@
1
+ # Omnipass
2
+
3
+ Welcome to your new gem! In this directory, you'll find the files you need to be able to package up your Ruby library into a gem. Put your Ruby code in the file `lib/omnipass`. To experiment with that code, run `bin/console` for an interactive prompt.
4
+
5
+ TODO: Delete this and the text above, and describe your gem
6
+
7
+ ## Installation
8
+
9
+ Add this line to your application's Gemfile:
10
+
11
+ ```ruby
12
+ gem 'omnipass'
13
+ ```
14
+
15
+ And then execute:
16
+
17
+ $ bundle
18
+
19
+ Or install it yourself as:
20
+
21
+ $ gem install omnipass
22
+
23
+ ## Usage
24
+
25
+ TODO: Write usage instructions here
26
+
27
+ ## Development
28
+
29
+ After checking out the repo, run `bin/setup` to install dependencies. You can also run `bin/console` for an interactive prompt that will allow you to experiment.
30
+
31
+ 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](https://rubygems.org).
32
+
33
+ ## Contributing
34
+
35
+ Bug reports and pull requests are welcome on GitHub at https://github.com/[USERNAME]/omnipass.
36
+
37
+
38
+ ## License
39
+
40
+ The gem is available as open source under the terms of the [MIT License](http://opensource.org/licenses/MIT).
41
+
@@ -0,0 +1,8 @@
1
+ require "bundler/gem_tasks"
2
+
3
+ require 'rake/testtask'
4
+
5
+ Rake::TestTask.new do |t|
6
+ t.libs << 'test'
7
+ t.pattern = "test/*_test.rb"
8
+ end
@@ -0,0 +1,14 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require "bundler/setup"
4
+ require "omnipass"
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
@@ -0,0 +1,8 @@
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
@@ -0,0 +1,50 @@
1
+ module OmniAuth
2
+ module Strategies
3
+ # The identity strategy allows you to provide simple internal
4
+ # user authentication using the same process flow that you
5
+ # use for external OmniAuth providers.
6
+ class Identity
7
+ include OmniAuth::Strategy
8
+
9
+ option :fields, [:name, :email]
10
+ # option :on_login, nil
11
+ # option :on_rèegistration, nil
12
+ # option :on_failed_registration, nil
13
+ # option :locate_conditions, lambda{|req| {model.auth_key => req['auth_key']} }
14
+
15
+ def callback_phase
16
+ return fail!(:invalid_credentials) unless identity
17
+ super
18
+ end
19
+
20
+ uid { identity.uid }
21
+ info { identity.info }
22
+
23
+ def identity
24
+ if request["session"]
25
+ find_identity_with_session
26
+ else
27
+ find_identity_with_token
28
+ end
29
+ end
30
+
31
+ def model
32
+ options[:model] || Users::Identity
33
+ end
34
+
35
+ private
36
+ def find_identity_with_session
37
+ @identity ||= ::Users::Identity.authenticate(
38
+ # request["session"].slice("email"),
39
+ # request["session"]['password']
40
+ request["session"]
41
+ )
42
+ end
43
+
44
+ def find_identity_with_token
45
+ @identity||= ::Users::Identity.find_by_token request["confirmation_token"]
46
+ end
47
+
48
+ end
49
+ end
50
+ end
@@ -0,0 +1,10 @@
1
+ require "omnipass/version"
2
+
3
+ require "omniauth/strategies/email"
4
+
5
+ require "omnipass/email"
6
+ # require "omnipass"
7
+
8
+ module Omnipass
9
+ # Your code goes here...
10
+ end
@@ -0,0 +1,52 @@
1
+ module Omnipass
2
+ class Authenticate
3
+
4
+ include Virtus.model
5
+ include ActiveModel::Model
6
+
7
+ attribute :provider
8
+ attribute :uid
9
+ attribute :info, Hash
10
+ attribute :credentials, Hash
11
+
12
+ validates :provider, :uid, :info, presence: true
13
+
14
+ # instantiate OmniauthSession with the controller env
15
+ def self.build( omni_hash )
16
+ self.new omni_hash.slice("provider", "uid", "info", "credentials")
17
+ end
18
+
19
+ def email
20
+ info.fetch("email") { "nomail" }
21
+ end
22
+
23
+ def save
24
+ link_or_create_account
25
+ authentication.transaction do
26
+ saved = authentication.save
27
+ # user.create_account
28
+ # binding.pry
29
+ saved
30
+ end
31
+ end
32
+
33
+ def authentication
34
+ @authentication ||= Users::Authentication.
35
+ where(attributes.slice(:provider, :uid)).first_or_create
36
+ end
37
+
38
+ # DEPRECATED
39
+ # def user
40
+ # @user ||= User.where(email: email).first_or_initialize
41
+ # end
42
+
43
+ def account
44
+ @account ||= Account.where(email: email).first_or_initialize
45
+ end
46
+
47
+ private
48
+ def link_or_create_account
49
+ authentication.account || (authentication.account = account)
50
+ end
51
+ end
52
+ end
@@ -0,0 +1,17 @@
1
+
2
+ module Omnipass
3
+ class Authentication < ActiveRecord::Base
4
+ belongs_to :user
5
+ belongs_to :account
6
+
7
+ # CAUTION : this can be used in a has_on :through: :authentications
8
+ belongs_to :identity, class_name: "Users::Identity"
9
+
10
+ # before_save :copy_uid_to_identity_id # uncomment after migration
11
+
12
+ def copy_uid_to_identity_id
13
+ self.identity_id = uid if provider == "identity"
14
+ end
15
+
16
+ end
17
+ end
@@ -0,0 +1,57 @@
1
+ #
2
+ #
3
+ #
4
+ #
5
+ module Omnipass
6
+ class Email < ActiveRecord::Base
7
+ self.table_name = 'identities'
8
+ has_secure_password
9
+ paramount
10
+ # paramount :form_admin, Admin::ScanForm
11
+
12
+ validates :email, uniqueness: true
13
+
14
+ def self.find_by_token(token)
15
+ unless token.blank?
16
+ all.where(confirmation_token: token).first
17
+ end
18
+ end
19
+
20
+ def self.authenticate(params)
21
+ login_pass_hash = params.symbolize_keys
22
+
23
+ instance = locate(login_pass_hash.slice(:email))
24
+ return false unless instance
25
+ instance.authenticate(login_pass_hash[:password])
26
+ end
27
+
28
+ def self.locate(search_hash)
29
+ where(search_hash).first
30
+ end
31
+
32
+ alias uid id
33
+
34
+ def info
35
+ {name: email, email: email}
36
+ end
37
+
38
+ def generate_confirmation_token
39
+ self.confirmation_token = SecureRandom.base58(24)
40
+ end
41
+
42
+ def confirm
43
+ generate_confirmation_token
44
+ self.confirmed_at= Time.now.utc
45
+ save
46
+ end
47
+
48
+ def confirmed?
49
+ !!confirmed_at
50
+ end
51
+
52
+ def form_admin(params = nil)
53
+ Admin::Users::IdentityForm.new(params, self)
54
+ end
55
+
56
+ end
57
+ end
@@ -0,0 +1,3 @@
1
+ module Omnipass
2
+ VERSION = "0.0.1"
3
+ end
@@ -0,0 +1,39 @@
1
+ # coding: utf-8
2
+ lib = File.expand_path('../lib', __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require 'omnipass/version'
5
+
6
+ Gem::Specification.new do |spec|
7
+ spec.name = "omnipass"
8
+ spec.version = Omnipass::VERSION
9
+ spec.authors = ["Charles Sistovaris"]
10
+ spec.email = ["charlysisto@gmail.com"]
11
+
12
+ spec.summary = %q{Authentication done well}
13
+ spec.description = %q{Authentication done well}
14
+ spec.homepage = "http://github.com/charly/omnipass"
15
+ spec.license = "MIT"
16
+
17
+ # Prevent pushing this gem to RubyGems.org by setting 'allowed_push_host', or
18
+ # delete this section to allow pushing this gem to any host.
19
+ # if spec.respond_to?(:metadata)
20
+ # spec.metadata['allowed_push_host'] = "TODO: Set to 'http://mygemserver.com'"
21
+ # else
22
+ # raise "RubyGems 2.0 or newer is required to protect against public gem pushes."
23
+ # end
24
+
25
+ spec.files = `git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features)/}) }
26
+ spec.bindir = "exe"
27
+ spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
28
+ spec.require_paths = ["lib"]
29
+
30
+ spec.add_dependency "activesupport", "~> 4"
31
+ spec.add_dependency "virtus", "~> 1"
32
+
33
+ spec.add_development_dependency "bundler", "~> 1.11"
34
+ spec.add_development_dependency "rake", "~> 10.0"
35
+
36
+ spec.add_development_dependency "minitest", "~> 4.7"
37
+ spec.add_development_dependency "activerecord", "~> 4"
38
+ spec.add_development_dependency "sqlite3"
39
+ end
metadata ADDED
@@ -0,0 +1,156 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: omnipass
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.1
5
+ platform: ruby
6
+ authors:
7
+ - Charles Sistovaris
8
+ autorequire:
9
+ bindir: exe
10
+ cert_chain: []
11
+ date: 2016-06-14 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: activesupport
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - "~>"
18
+ - !ruby/object:Gem::Version
19
+ version: '4'
20
+ type: :runtime
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - "~>"
25
+ - !ruby/object:Gem::Version
26
+ version: '4'
27
+ - !ruby/object:Gem::Dependency
28
+ name: virtus
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - "~>"
32
+ - !ruby/object:Gem::Version
33
+ version: '1'
34
+ type: :runtime
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - "~>"
39
+ - !ruby/object:Gem::Version
40
+ version: '1'
41
+ - !ruby/object:Gem::Dependency
42
+ name: bundler
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - "~>"
46
+ - !ruby/object:Gem::Version
47
+ version: '1.11'
48
+ type: :development
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - "~>"
53
+ - !ruby/object:Gem::Version
54
+ version: '1.11'
55
+ - !ruby/object:Gem::Dependency
56
+ name: rake
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - "~>"
60
+ - !ruby/object:Gem::Version
61
+ version: '10.0'
62
+ type: :development
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - "~>"
67
+ - !ruby/object:Gem::Version
68
+ version: '10.0'
69
+ - !ruby/object:Gem::Dependency
70
+ name: minitest
71
+ requirement: !ruby/object:Gem::Requirement
72
+ requirements:
73
+ - - "~>"
74
+ - !ruby/object:Gem::Version
75
+ version: '4.7'
76
+ type: :development
77
+ prerelease: false
78
+ version_requirements: !ruby/object:Gem::Requirement
79
+ requirements:
80
+ - - "~>"
81
+ - !ruby/object:Gem::Version
82
+ version: '4.7'
83
+ - !ruby/object:Gem::Dependency
84
+ name: activerecord
85
+ requirement: !ruby/object:Gem::Requirement
86
+ requirements:
87
+ - - "~>"
88
+ - !ruby/object:Gem::Version
89
+ version: '4'
90
+ type: :development
91
+ prerelease: false
92
+ version_requirements: !ruby/object:Gem::Requirement
93
+ requirements:
94
+ - - "~>"
95
+ - !ruby/object:Gem::Version
96
+ version: '4'
97
+ - !ruby/object:Gem::Dependency
98
+ name: sqlite3
99
+ requirement: !ruby/object:Gem::Requirement
100
+ requirements:
101
+ - - ">="
102
+ - !ruby/object:Gem::Version
103
+ version: '0'
104
+ type: :development
105
+ prerelease: false
106
+ version_requirements: !ruby/object:Gem::Requirement
107
+ requirements:
108
+ - - ">="
109
+ - !ruby/object:Gem::Version
110
+ version: '0'
111
+ description: Authentication done well
112
+ email:
113
+ - charlysisto@gmail.com
114
+ executables: []
115
+ extensions: []
116
+ extra_rdoc_files: []
117
+ files:
118
+ - ".gitignore"
119
+ - Gemfile
120
+ - LICENSE.txt
121
+ - README.md
122
+ - Rakefile
123
+ - bin/console
124
+ - bin/setup
125
+ - lib/omniauth/strategies/email.rb
126
+ - lib/omnipass.rb
127
+ - lib/omnipass/authenticate.rb
128
+ - lib/omnipass/authentication.rb
129
+ - lib/omnipass/email.rb
130
+ - lib/omnipass/version.rb
131
+ - omnipass.gemspec
132
+ homepage: http://github.com/charly/omnipass
133
+ licenses:
134
+ - MIT
135
+ metadata: {}
136
+ post_install_message:
137
+ rdoc_options: []
138
+ require_paths:
139
+ - lib
140
+ required_ruby_version: !ruby/object:Gem::Requirement
141
+ requirements:
142
+ - - ">="
143
+ - !ruby/object:Gem::Version
144
+ version: '0'
145
+ required_rubygems_version: !ruby/object:Gem::Requirement
146
+ requirements:
147
+ - - ">="
148
+ - !ruby/object:Gem::Version
149
+ version: '0'
150
+ requirements: []
151
+ rubyforge_project:
152
+ rubygems_version: 2.4.5.1
153
+ signing_key:
154
+ specification_version: 4
155
+ summary: Authentication done well
156
+ test_files: []