stormpath-rails 0.2.0
Sign up to get free protection for your applications and to get access to all the features.
- data/.gitignore +18 -0
- data/Gemfile +3 -0
- data/LICENSE.txt +22 -0
- data/README.md +31 -0
- data/Rakefile +1 -0
- data/lib/generators/stormpath/rails/config/config_generator.rb +22 -0
- data/lib/stormpath-rails/account.rb +62 -0
- data/lib/stormpath-rails/client.rb +44 -0
- data/lib/stormpath-rails/version.rb +5 -0
- data/lib/stormpath-rails.rb +16 -0
- data/stormpath-rails.gemspec +20 -0
- metadata +88 -0
data/.gitignore
ADDED
data/Gemfile
ADDED
data/LICENSE.txt
ADDED
@@ -0,0 +1,22 @@
|
|
1
|
+
Copyright (c) 2012 Denis Grankin
|
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
|
+
# Stormpath::Rails
|
2
|
+
|
3
|
+
Ruby on Rails support for Stormpath
|
4
|
+
|
5
|
+
## Usage
|
6
|
+
|
7
|
+
add gem 'stormpath-rails' to Gemfile
|
8
|
+
|
9
|
+
run rails g stormpath:rails:install
|
10
|
+
|
11
|
+
edit config/stormpath.yml
|
12
|
+
|
13
|
+
export stormpath connection string to STORMPATH_URL (optional)
|
14
|
+
|
15
|
+
class User < ActiveRecord:Base
|
16
|
+
include Stormpath::Rails::Account
|
17
|
+
end
|
18
|
+
|
19
|
+
add stormpath_url column to store stormpath UID.
|
20
|
+
|
21
|
+
## TODO
|
22
|
+
|
23
|
+
Preventive validation to not send invalid data to stormpath.
|
24
|
+
|
25
|
+
## Contributing
|
26
|
+
|
27
|
+
1. Fork it
|
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 new Pull Request
|
data/Rakefile
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
require "bundler/gem_tasks"
|
@@ -0,0 +1,22 @@
|
|
1
|
+
module Stormpath
|
2
|
+
module Rails
|
3
|
+
module Generators
|
4
|
+
class ConfigGenerator < ::Rails::Generators::Base
|
5
|
+
def create_initializer_file
|
6
|
+
create_file "config/stormpath.yml", "development:
|
7
|
+
href: <%= ENV['STORMPATH_URL'] %>
|
8
|
+
root: https://api.stormpath.com/v1/directories/<root directory uid>
|
9
|
+
|
10
|
+
test:
|
11
|
+
href: <%= ENV['STORMPATH_URL'] %>
|
12
|
+
root: https://api.stormpath.com/v1/directories/<root directory uid>
|
13
|
+
|
14
|
+
production:
|
15
|
+
href: <%= ENV['STORMPATH_URL'] %>
|
16
|
+
root: https://api.stormpath.com/v1/directories/<root directory uid>
|
17
|
+
"
|
18
|
+
end
|
19
|
+
end
|
20
|
+
end
|
21
|
+
end
|
22
|
+
end
|
@@ -0,0 +1,62 @@
|
|
1
|
+
require 'active_support/concern'
|
2
|
+
require "stormpath-sdk"
|
3
|
+
include Stormpath::Client
|
4
|
+
include Stormpath::Resource
|
5
|
+
|
6
|
+
module Stormpath
|
7
|
+
module Rails
|
8
|
+
module Account
|
9
|
+
extend ActiveSupport::Concern
|
10
|
+
|
11
|
+
STORMPATH_FIELDS = [ :email, :password, :username, :given_name, :middle_name, :surname ]
|
12
|
+
|
13
|
+
included do
|
14
|
+
self.partial_updates = false
|
15
|
+
|
16
|
+
attr_accessor *STORMPATH_FIELDS
|
17
|
+
attr_accessible *STORMPATH_FIELDS
|
18
|
+
|
19
|
+
after_initialize do |user|
|
20
|
+
return unless user.stormpath_url
|
21
|
+
begin
|
22
|
+
account = Client.find_account(user.stormpath_url)
|
23
|
+
(STORMPATH_FIELDS - [:password]).each { |field| self.send("#{field}=", account.send("get_#{field}")) }
|
24
|
+
rescue => e
|
25
|
+
#somehow mark as data not loaded
|
26
|
+
end
|
27
|
+
end
|
28
|
+
|
29
|
+
before_create do
|
30
|
+
begin
|
31
|
+
account = Client.create_account!(Hash[*STORMPATH_FIELDS.map { |f| { f => self.send(f) } }.map(&:to_a).flatten])
|
32
|
+
rescue ResourceError => error
|
33
|
+
self.errors[:base] << error.to_s
|
34
|
+
return false
|
35
|
+
end
|
36
|
+
self.stormpath_url = account.get_href
|
37
|
+
end
|
38
|
+
|
39
|
+
before_update do
|
40
|
+
begin
|
41
|
+
account = Client.update_account!(self.stormpath_url, Hash[*STORMPATH_FIELDS.map { |f| { f => self.send(f) } }.map(&:to_a).flatten])
|
42
|
+
rescue ResourceError => error
|
43
|
+
self.errors[:base] << error.to_s
|
44
|
+
return nil
|
45
|
+
end
|
46
|
+
end
|
47
|
+
|
48
|
+
after_destroy do
|
49
|
+
begin
|
50
|
+
account = Client.delete_account!(self.stormpath_url)
|
51
|
+
rescue ResourceError => error
|
52
|
+
self.errors[:base] << error.to_s
|
53
|
+
return false
|
54
|
+
end
|
55
|
+
end
|
56
|
+
end
|
57
|
+
|
58
|
+
module ClassMethods
|
59
|
+
end
|
60
|
+
end
|
61
|
+
end
|
62
|
+
end
|
@@ -0,0 +1,44 @@
|
|
1
|
+
require "stormpath-sdk"
|
2
|
+
include Stormpath::Client
|
3
|
+
include Stormpath::Resource
|
4
|
+
|
5
|
+
module Stormpath
|
6
|
+
module Rails
|
7
|
+
class Client
|
8
|
+
cattr_accessor :_connection
|
9
|
+
|
10
|
+
def self.create_account!(attributes)
|
11
|
+
account = self.ds.instantiate ::Account
|
12
|
+
attributes.each { |field, value| account.send("set_#{field}", value) }
|
13
|
+
self.root_directory.create_account account
|
14
|
+
end
|
15
|
+
|
16
|
+
def self.all_accounts
|
17
|
+
self.root_directory.get_accounts
|
18
|
+
end
|
19
|
+
|
20
|
+
def self.find_account(href)
|
21
|
+
self.ds.get_resource href, ::Account
|
22
|
+
end
|
23
|
+
|
24
|
+
def self.update_account!(href, attributes)
|
25
|
+
account = self.ds.get_resource href, ::Account
|
26
|
+
attributes.each { |field, value| account.send("set_#{field}", value) }
|
27
|
+
account.save
|
28
|
+
end
|
29
|
+
|
30
|
+
def self.delete_account!(href)
|
31
|
+
self.ds.delete self.ds.get_resource href, ::Account
|
32
|
+
end
|
33
|
+
|
34
|
+
def self.root_directory
|
35
|
+
self.ds.get_resource Config[:root], ::Directory
|
36
|
+
end
|
37
|
+
|
38
|
+
def self.ds
|
39
|
+
self._connection ||= ::ClientApplicationBuilder.new.set_application_href(Config[:href]).build
|
40
|
+
self._connection.client.data_store
|
41
|
+
end
|
42
|
+
end
|
43
|
+
end
|
44
|
+
end
|
@@ -0,0 +1,16 @@
|
|
1
|
+
require "stormpath-rails/version"
|
2
|
+
require "stormpath-rails/client"
|
3
|
+
require "stormpath-rails/account"
|
4
|
+
|
5
|
+
module Stormpath
|
6
|
+
module Rails
|
7
|
+
class Config
|
8
|
+
cattr_accessor :_variables
|
9
|
+
|
10
|
+
def self.[](name)
|
11
|
+
self._variables ||= YAML.load(ERB.new(File.read("#{::Rails.root}/config/stormpath.yml")).result)[::Rails.env]
|
12
|
+
self._variables[name.to_s]
|
13
|
+
end
|
14
|
+
end
|
15
|
+
end
|
16
|
+
end
|
@@ -0,0 +1,20 @@
|
|
1
|
+
# -*- encoding: utf-8 -*-
|
2
|
+
lib = File.expand_path('../lib', __FILE__)
|
3
|
+
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
4
|
+
require 'stormpath-rails/version'
|
5
|
+
|
6
|
+
Gem::Specification.new do |gem|
|
7
|
+
gem.name = "stormpath-rails"
|
8
|
+
gem.version = Stormpath::Rails::VERSION
|
9
|
+
gem.authors = ["Denis Grankin"]
|
10
|
+
gem.email = ["liquidautumn@gmail.com"]
|
11
|
+
gem.description = %q{Stormpath Rails integration}
|
12
|
+
gem.summary = %q{Stormpath SDK API Wrapper}
|
13
|
+
|
14
|
+
gem.add_dependency "activesupport"
|
15
|
+
gem.add_dependency "stormpath-sdk"
|
16
|
+
|
17
|
+
gem.files = `git ls-files`.split($/)
|
18
|
+
gem.test_files = gem.files.grep(%r{^(test|spec|features)/})
|
19
|
+
gem.require_paths = ["lib"]
|
20
|
+
end
|
metadata
ADDED
@@ -0,0 +1,88 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: stormpath-rails
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.2.0
|
5
|
+
prerelease:
|
6
|
+
platform: ruby
|
7
|
+
authors:
|
8
|
+
- Denis Grankin
|
9
|
+
autorequire:
|
10
|
+
bindir: bin
|
11
|
+
cert_chain: []
|
12
|
+
date: 2012-10-18 00:00:00.000000000 Z
|
13
|
+
dependencies:
|
14
|
+
- !ruby/object:Gem::Dependency
|
15
|
+
name: activesupport
|
16
|
+
requirement: !ruby/object:Gem::Requirement
|
17
|
+
none: false
|
18
|
+
requirements:
|
19
|
+
- - ! '>='
|
20
|
+
- !ruby/object:Gem::Version
|
21
|
+
version: '0'
|
22
|
+
type: :runtime
|
23
|
+
prerelease: false
|
24
|
+
version_requirements: !ruby/object:Gem::Requirement
|
25
|
+
none: false
|
26
|
+
requirements:
|
27
|
+
- - ! '>='
|
28
|
+
- !ruby/object:Gem::Version
|
29
|
+
version: '0'
|
30
|
+
- !ruby/object:Gem::Dependency
|
31
|
+
name: stormpath-sdk
|
32
|
+
requirement: !ruby/object:Gem::Requirement
|
33
|
+
none: false
|
34
|
+
requirements:
|
35
|
+
- - ! '>='
|
36
|
+
- !ruby/object:Gem::Version
|
37
|
+
version: '0'
|
38
|
+
type: :runtime
|
39
|
+
prerelease: false
|
40
|
+
version_requirements: !ruby/object:Gem::Requirement
|
41
|
+
none: false
|
42
|
+
requirements:
|
43
|
+
- - ! '>='
|
44
|
+
- !ruby/object:Gem::Version
|
45
|
+
version: '0'
|
46
|
+
description: Stormpath Rails integration
|
47
|
+
email:
|
48
|
+
- liquidautumn@gmail.com
|
49
|
+
executables: []
|
50
|
+
extensions: []
|
51
|
+
extra_rdoc_files: []
|
52
|
+
files:
|
53
|
+
- .gitignore
|
54
|
+
- Gemfile
|
55
|
+
- LICENSE.txt
|
56
|
+
- README.md
|
57
|
+
- Rakefile
|
58
|
+
- lib/generators/stormpath/rails/config/config_generator.rb
|
59
|
+
- lib/stormpath-rails.rb
|
60
|
+
- lib/stormpath-rails/account.rb
|
61
|
+
- lib/stormpath-rails/client.rb
|
62
|
+
- lib/stormpath-rails/version.rb
|
63
|
+
- stormpath-rails.gemspec
|
64
|
+
homepage:
|
65
|
+
licenses: []
|
66
|
+
post_install_message:
|
67
|
+
rdoc_options: []
|
68
|
+
require_paths:
|
69
|
+
- lib
|
70
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
71
|
+
none: false
|
72
|
+
requirements:
|
73
|
+
- - ! '>='
|
74
|
+
- !ruby/object:Gem::Version
|
75
|
+
version: '0'
|
76
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
77
|
+
none: false
|
78
|
+
requirements:
|
79
|
+
- - ! '>='
|
80
|
+
- !ruby/object:Gem::Version
|
81
|
+
version: '0'
|
82
|
+
requirements: []
|
83
|
+
rubyforge_project:
|
84
|
+
rubygems_version: 1.8.24
|
85
|
+
signing_key:
|
86
|
+
specification_version: 3
|
87
|
+
summary: Stormpath SDK API Wrapper
|
88
|
+
test_files: []
|