omniauth-applicaster 1.0.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/.gitignore +14 -0
- data/Gemfile +4 -0
- data/LICENSE.txt +22 -0
- data/README.md +31 -0
- data/Rakefile +2 -0
- data/lib/applicaster/accounts.rb +42 -0
- data/lib/applicaster/auth_helpers.rb +43 -0
- data/lib/applicaster/sessions_controller_mixin.rb +43 -0
- data/lib/applicaster/user.rb +38 -0
- data/lib/omniauth/strategies/applicaster.rb +36 -0
- data/lib/omniauth-applicaster/version.rb +5 -0
- data/lib/omniauth-applicaster.rb +5 -0
- data/omniauth-applicaster.gemspec +24 -0
- metadata +99 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: 55f41c66db9dcddd730cfaf7f4535dd210ddd90b
|
4
|
+
data.tar.gz: bda52dd514bccbc9f3de76caffa911040782b2c0
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: 89c76d047d4cbce87e7fa018f2c20c2421a61acda659a3c05db97316571e2dce5e93150f908377c860b55af14ea20366909ce9b2079975d4732064a6a69f5560
|
7
|
+
data.tar.gz: 94f626aebca848a22fd14f123c1335482eda26e316e0b582f610798904410d0457682b9cdfc119d53cdf39a99e05e071c5fb1734641a98a8b6e30c48f81b029c
|
data/.gitignore
ADDED
data/Gemfile
ADDED
data/LICENSE.txt
ADDED
@@ -0,0 +1,22 @@
|
|
1
|
+
Copyright (c) 2014 Neer Friedman
|
2
|
+
|
3
|
+
MIT License
|
4
|
+
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining
|
6
|
+
a copy of this software and associated documentation files (the
|
7
|
+
"Software"), to deal in the Software without restriction, including
|
8
|
+
without limitation the rights to use, copy, modify, merge, publish,
|
9
|
+
distribute, sublicense, and/or sell copies of the Software, and to
|
10
|
+
permit persons to whom the Software is furnished to do so, subject to
|
11
|
+
the following conditions:
|
12
|
+
|
13
|
+
The above copyright notice and this permission notice shall be
|
14
|
+
included in all copies or substantial portions of the Software.
|
15
|
+
|
16
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
17
|
+
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
18
|
+
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
19
|
+
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
20
|
+
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
21
|
+
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
22
|
+
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
data/README.md
ADDED
@@ -0,0 +1,31 @@
|
|
1
|
+
# Omniauth::Applicaster
|
2
|
+
|
3
|
+
TODO: Write a gem description
|
4
|
+
|
5
|
+
## Installation
|
6
|
+
|
7
|
+
Add this line to your application's Gemfile:
|
8
|
+
|
9
|
+
```ruby
|
10
|
+
gem 'omniauth-applicaster'
|
11
|
+
```
|
12
|
+
|
13
|
+
And then execute:
|
14
|
+
|
15
|
+
$ bundle
|
16
|
+
|
17
|
+
Or install it yourself as:
|
18
|
+
|
19
|
+
$ gem install omniauth-applicaster
|
20
|
+
|
21
|
+
## Usage
|
22
|
+
|
23
|
+
TODO: Write usage instructions here
|
24
|
+
|
25
|
+
## Contributing
|
26
|
+
|
27
|
+
1. Fork it ( https://github.com/[my-github-username]/omniauth-applicaster/fork )
|
28
|
+
2. Create your feature branch (`git checkout -b my-new-feature`)
|
29
|
+
3. Commit your changes (`git commit -am 'Add some feature'`)
|
30
|
+
4. Push to the branch (`git push origin my-new-feature`)
|
31
|
+
5. Create a new Pull Request
|
data/Rakefile
ADDED
@@ -0,0 +1,42 @@
|
|
1
|
+
module Applicaster
|
2
|
+
class Accounts
|
3
|
+
attr_accessor :client_id
|
4
|
+
attr_accessor :client_secret
|
5
|
+
|
6
|
+
class << self
|
7
|
+
def default_site
|
8
|
+
"http://accounts2.applicaster.com"
|
9
|
+
end
|
10
|
+
|
11
|
+
def site
|
12
|
+
URI.parse(ENV["ACCOUNTS_BASE_URL"] || default_site)
|
13
|
+
end
|
14
|
+
end
|
15
|
+
|
16
|
+
def initialize(client_id, client_secret)
|
17
|
+
@client_id = client_id
|
18
|
+
@client_secret = client_secret
|
19
|
+
end
|
20
|
+
|
21
|
+
def user_data_from_omniauth(omniauth_credentials)
|
22
|
+
access_token(omniauth_credentials).get("/api/v1/users/current.json").parsed
|
23
|
+
end
|
24
|
+
|
25
|
+
def client
|
26
|
+
@client ||= ::OAuth2::Client.new(
|
27
|
+
client_id,
|
28
|
+
client_secret,
|
29
|
+
site: Applicaster::Accounts.site,
|
30
|
+
authorize_url: "/oauth/authorize",
|
31
|
+
)
|
32
|
+
end
|
33
|
+
|
34
|
+
def access_token(omniauth_credentials)
|
35
|
+
@access_token ||= OAuth2::AccessToken.new(
|
36
|
+
client,
|
37
|
+
omniauth_credentials["token"],
|
38
|
+
omniauth_credentials.except("token", "expires"),
|
39
|
+
)
|
40
|
+
end
|
41
|
+
end
|
42
|
+
end
|
@@ -0,0 +1,43 @@
|
|
1
|
+
require_relative "user"
|
2
|
+
|
3
|
+
module Applicaster
|
4
|
+
module AuthHelpers
|
5
|
+
def current_user
|
6
|
+
return nil unless session[:omniauth_credentials]
|
7
|
+
|
8
|
+
@current_user ||= user_from_session.tap do |user|
|
9
|
+
session.delete(:omniauth_credentials) unless user
|
10
|
+
end
|
11
|
+
rescue OAuth2::Error => e
|
12
|
+
session.delete(:omniauth_credentials)
|
13
|
+
nil
|
14
|
+
end
|
15
|
+
|
16
|
+
def user_signed_in?
|
17
|
+
!current_user.nil?
|
18
|
+
end
|
19
|
+
|
20
|
+
protected
|
21
|
+
|
22
|
+
def authenticate_user!
|
23
|
+
unless current_user
|
24
|
+
session[:path_before_login] = url_for(params)
|
25
|
+
redirect_to '/auth/applicaster'
|
26
|
+
end
|
27
|
+
end
|
28
|
+
|
29
|
+
def user_from_session
|
30
|
+
Applicaster::User.new(
|
31
|
+
accounts_client.user_data_from_omniauth(session[:omniauth_credentials])
|
32
|
+
)
|
33
|
+
end
|
34
|
+
|
35
|
+
def accounts_client
|
36
|
+
Applicaster::Accounts.new(
|
37
|
+
Settings.accounts_service.id,
|
38
|
+
Settings.accounts_service.secret,
|
39
|
+
)
|
40
|
+
end
|
41
|
+
end
|
42
|
+
end
|
43
|
+
|
@@ -0,0 +1,43 @@
|
|
1
|
+
module Applicaster
|
2
|
+
module SessionsControllerMixin
|
3
|
+
def new
|
4
|
+
redirect_to "/auth/applicaster"
|
5
|
+
end
|
6
|
+
|
7
|
+
def create
|
8
|
+
session[:omniauth_credentials] = auth_hash.credentials.to_hash
|
9
|
+
|
10
|
+
redirect_to(session.delete(:path_before_login) || '/')
|
11
|
+
end
|
12
|
+
|
13
|
+
def destroy
|
14
|
+
reset_session
|
15
|
+
|
16
|
+
redirect_to "/"
|
17
|
+
end
|
18
|
+
|
19
|
+
def failure
|
20
|
+
Rails.logger.warn({
|
21
|
+
message: "Omniauth error with strategy '#{params[:strategy]}': #{params[:message]}",
|
22
|
+
origin: params[:origin],
|
23
|
+
})
|
24
|
+
flash[:notice] = "There was a problem logging in"
|
25
|
+
redirect_to "/"
|
26
|
+
end
|
27
|
+
|
28
|
+
protected
|
29
|
+
|
30
|
+
def auth_hash
|
31
|
+
request.env['omniauth.auth']
|
32
|
+
end
|
33
|
+
|
34
|
+
def access_token
|
35
|
+
@access_token ||= OAuth2::AccessToken.new(
|
36
|
+
client,
|
37
|
+
auth_hash.credentials.token,
|
38
|
+
auth_hash.credentials.to_hash.except("token", "expires"),
|
39
|
+
)
|
40
|
+
end
|
41
|
+
|
42
|
+
end
|
43
|
+
end
|
@@ -0,0 +1,38 @@
|
|
1
|
+
module Applicaster
|
2
|
+
class User
|
3
|
+
attr_accessor :user_json
|
4
|
+
|
5
|
+
def initialize(user_json)
|
6
|
+
@user_json = user_json.symbolize_keys
|
7
|
+
end
|
8
|
+
|
9
|
+
def id
|
10
|
+
user_json[:id]
|
11
|
+
end
|
12
|
+
|
13
|
+
def name
|
14
|
+
user_json[:name]
|
15
|
+
end
|
16
|
+
|
17
|
+
def email
|
18
|
+
user_json[:email]
|
19
|
+
end
|
20
|
+
|
21
|
+
def global_roles
|
22
|
+
user_json[:global_roles]
|
23
|
+
end
|
24
|
+
|
25
|
+
def permissions
|
26
|
+
user_json[:permissions]
|
27
|
+
end
|
28
|
+
|
29
|
+
def admin
|
30
|
+
puts user_json.inspect
|
31
|
+
user_json[:admin]
|
32
|
+
end
|
33
|
+
|
34
|
+
def admin?
|
35
|
+
!!admin
|
36
|
+
end
|
37
|
+
end
|
38
|
+
end
|
@@ -0,0 +1,36 @@
|
|
1
|
+
require "omniauth-oauth2"
|
2
|
+
require "applicaster/accounts"
|
3
|
+
|
4
|
+
module OmniAuth
|
5
|
+
module Strategies
|
6
|
+
class Applicaster < OmniAuth::Strategies::OAuth2
|
7
|
+
option :name, :applicaster
|
8
|
+
|
9
|
+
uid { raw_info["id"] }
|
10
|
+
|
11
|
+
info do
|
12
|
+
{
|
13
|
+
name: raw_info["name"],
|
14
|
+
email: raw_info["email"],
|
15
|
+
admin: raw_info["admin"],
|
16
|
+
account_id: raw_info["account_id"],
|
17
|
+
global_roles: raw_info["global_roles"],
|
18
|
+
permissions: raw_info["permissions"],
|
19
|
+
}
|
20
|
+
end
|
21
|
+
|
22
|
+
def raw_info
|
23
|
+
@raw_info ||= access_token.get('/api/v1/users/current.json').parsed
|
24
|
+
end
|
25
|
+
|
26
|
+
def client
|
27
|
+
::OAuth2::Client.new(
|
28
|
+
options.client_id,
|
29
|
+
options.client_secret,
|
30
|
+
site: ::Applicaster::Accounts.site,
|
31
|
+
authorize_url: "/oauth/authorize",
|
32
|
+
)
|
33
|
+
end
|
34
|
+
end
|
35
|
+
end
|
36
|
+
end
|
@@ -0,0 +1,24 @@
|
|
1
|
+
# coding: utf-8
|
2
|
+
lib = File.expand_path('../lib', __FILE__)
|
3
|
+
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
4
|
+
require 'omniauth-applicaster/version'
|
5
|
+
|
6
|
+
Gem::Specification.new do |spec|
|
7
|
+
spec.name = "omniauth-applicaster"
|
8
|
+
spec.version = Omniauth::Applicaster::VERSION
|
9
|
+
spec.authors = ["Neer Friedman"]
|
10
|
+
spec.email = ["neerfri@gmail.com"]
|
11
|
+
spec.summary = %q{Omniauth strategy for http://accounts.applicaster.com}
|
12
|
+
spec.description = %q{Omniauth strategy for http://accounts.applicaster.com}
|
13
|
+
spec.homepage = ""
|
14
|
+
spec.license = "MIT"
|
15
|
+
|
16
|
+
spec.files = `git ls-files -z`.split("\x0")
|
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.7"
|
22
|
+
spec.add_development_dependency "rake", "~> 10.0"
|
23
|
+
spec.add_dependency "omniauth-oauth2"
|
24
|
+
end
|
metadata
ADDED
@@ -0,0 +1,99 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: omniauth-applicaster
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 1.0.0
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Neer Friedman
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
date: 2015-01-05 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.7'
|
20
|
+
type: :development
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - "~>"
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: '1.7'
|
27
|
+
- !ruby/object:Gem::Dependency
|
28
|
+
name: rake
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - "~>"
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: '10.0'
|
34
|
+
type: :development
|
35
|
+
prerelease: false
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - "~>"
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: '10.0'
|
41
|
+
- !ruby/object:Gem::Dependency
|
42
|
+
name: omniauth-oauth2
|
43
|
+
requirement: !ruby/object:Gem::Requirement
|
44
|
+
requirements:
|
45
|
+
- - ">="
|
46
|
+
- !ruby/object:Gem::Version
|
47
|
+
version: '0'
|
48
|
+
type: :runtime
|
49
|
+
prerelease: false
|
50
|
+
version_requirements: !ruby/object:Gem::Requirement
|
51
|
+
requirements:
|
52
|
+
- - ">="
|
53
|
+
- !ruby/object:Gem::Version
|
54
|
+
version: '0'
|
55
|
+
description: Omniauth strategy for http://accounts.applicaster.com
|
56
|
+
email:
|
57
|
+
- neerfri@gmail.com
|
58
|
+
executables: []
|
59
|
+
extensions: []
|
60
|
+
extra_rdoc_files: []
|
61
|
+
files:
|
62
|
+
- ".gitignore"
|
63
|
+
- Gemfile
|
64
|
+
- LICENSE.txt
|
65
|
+
- README.md
|
66
|
+
- Rakefile
|
67
|
+
- lib/applicaster/accounts.rb
|
68
|
+
- lib/applicaster/auth_helpers.rb
|
69
|
+
- lib/applicaster/sessions_controller_mixin.rb
|
70
|
+
- lib/applicaster/user.rb
|
71
|
+
- lib/omniauth-applicaster.rb
|
72
|
+
- lib/omniauth-applicaster/version.rb
|
73
|
+
- lib/omniauth/strategies/applicaster.rb
|
74
|
+
- omniauth-applicaster.gemspec
|
75
|
+
homepage: ''
|
76
|
+
licenses:
|
77
|
+
- MIT
|
78
|
+
metadata: {}
|
79
|
+
post_install_message:
|
80
|
+
rdoc_options: []
|
81
|
+
require_paths:
|
82
|
+
- lib
|
83
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
84
|
+
requirements:
|
85
|
+
- - ">="
|
86
|
+
- !ruby/object:Gem::Version
|
87
|
+
version: '0'
|
88
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
89
|
+
requirements:
|
90
|
+
- - ">="
|
91
|
+
- !ruby/object:Gem::Version
|
92
|
+
version: '0'
|
93
|
+
requirements: []
|
94
|
+
rubyforge_project:
|
95
|
+
rubygems_version: 2.2.2
|
96
|
+
signing_key:
|
97
|
+
specification_version: 4
|
98
|
+
summary: Omniauth strategy for http://accounts.applicaster.com
|
99
|
+
test_files: []
|