auth-transis-client 0.0.1

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,18 @@
1
+ *.gem
2
+ *.rbc
3
+ .bundle
4
+ .config
5
+ coverage
6
+ InstalledFiles
7
+ lib/bundler/man
8
+ pkg
9
+ rdoc
10
+ spec/reports
11
+ test/tmp
12
+ test/version_tmp
13
+ tmp
14
+
15
+ # YARD artifacts
16
+ .yardoc
17
+ _yardoc
18
+ doc/
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source 'https://rubygems.org'
2
+
3
+ # Specify your gem's dependencies in auth-transis-client.gemspec
4
+ gemspec
@@ -0,0 +1,22 @@
1
+ Copyright (c) 2012 Tim Galeckas
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.
@@ -0,0 +1,29 @@
1
+ # Auth::Transis::Client
2
+
3
+ TODO: Write a gem description
4
+
5
+ ## Installation
6
+
7
+ Add this line to your application's Gemfile:
8
+
9
+ gem 'auth-transis-client'
10
+
11
+ And then execute:
12
+
13
+ $ bundle
14
+
15
+ Or install it yourself as:
16
+
17
+ $ gem install auth-transis-client
18
+
19
+ ## Usage
20
+
21
+ TODO: Write usage instructions here
22
+
23
+ ## Contributing
24
+
25
+ 1. Fork it
26
+ 2. Create your feature branch (`git checkout -b my-new-feature`)
27
+ 3. Commit your changes (`git commit -am 'Add some feature'`)
28
+ 4. Push to the branch (`git push origin my-new-feature`)
29
+ 5. Create new Pull Request
@@ -0,0 +1 @@
1
+ require "bundler/gem_tasks"
@@ -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 'auth-transis-client/version'
5
+
6
+ Gem::Specification.new do |gem|
7
+ gem.name = "auth-transis-client"
8
+ gem.version = Auth::Transis::Client::VERSION
9
+ gem.authors = ["Tim Galeckas"]
10
+ gem.email = ["tim@galeckas.com"]
11
+ gem.description = %q{This is the client for TransisApps}
12
+ gem.summary = %q{See the description}
13
+ gem.homepage = ""
14
+
15
+ gem.files = `git ls-files`.split($/)
16
+ gem.executables = gem.files.grep(%r{^bin/}).map{ |f| File.basename(f) }
17
+ gem.test_files = gem.files.grep(%r{^(test|spec|features)/})
18
+ gem.require_paths = ["lib"]
19
+ gem.add_dependency ['omniauth', 'omniauth-oauth2' ]
20
+ end
@@ -0,0 +1,10 @@
1
+ require "auth-transis-client/version"
2
+ require "omni_auth"
3
+
4
+ module Auth
5
+ module Transis
6
+ module Client
7
+ # Your code goes here...
8
+ end
9
+ end
10
+ end
@@ -0,0 +1,7 @@
1
+ module Auth
2
+ module Transis
3
+ module Client
4
+ VERSION = "0.0.1"
5
+ end
6
+ end
7
+ end
@@ -0,0 +1,121 @@
1
+ module OmniAuth
2
+ module Strategies
3
+ class AuthTransis < OmniAuth::Strategies::OAuth2
4
+ option :name, :auth_transis
5
+
6
+ uid do
7
+ raw_info["id"]
8
+ end
9
+
10
+ info do
11
+ {
12
+ :email => raw_info["email"],
13
+ :organizations => raw_info['organizations'],
14
+ :features => raw_info['features']
15
+ }
16
+ end
17
+
18
+ def raw_info
19
+ @raw_info ||= access_token.get('/api/v1/me.json').parsed
20
+ end
21
+ end
22
+
23
+ class AuthTransisDeveloper
24
+ include OmniAuth::Strategy
25
+ option :name, :auth_transis_developer
26
+
27
+ option :fields, [:email]
28
+ option :uid_field, :email
29
+
30
+ def request_phase
31
+ form = OmniAuth::Form.new(:title => "Auth-Transis Developer Login", :url => callback_path, :header_info => <<-HTML)
32
+ <script src="//ajax.googleapis.com/ajax/libs/jquery/1.8.0/jquery.min.js"></script>
33
+ <script src="//ajax.googleapis.com/ajax/libs/jqueryui/1.8.23/jquery-ui.min.js"></script>
34
+
35
+ <link href="http://wwwendt.de/tech/dynatree/src/skin/ui.dynatree.css" rel="stylesheet" type="text/css">
36
+ <script src="http://wwwendt.de/tech/dynatree/src/jquery.dynatree.js" type="text/javascript"></script>
37
+ <script type="text/javascript">
38
+ var feature = function(organization_name, feature_name, selected){
39
+ return {title: feature_name, key: {organization_name: organization_name, feature_name: feature_name}, select: selected};
40
+ }
41
+ var organization = function(name, selected){
42
+ return {title: name, expand: true, key: name, children: [
43
+ feature(name,'admin',selected),
44
+ feature(name,'media_plan_creation',selected),
45
+ feature(name,'media_plan_negotiation',selected),
46
+ feature(name,'media_plan_analysis',selected),
47
+ feature(name,'finance',selected)
48
+ ]
49
+ }
50
+ }
51
+ var organizations = [
52
+ organization('Centro',true),
53
+ organization('TransisTestAgency',false),
54
+ organization('TransisTestPublisher',false),
55
+ ];
56
+ $(function(){
57
+ $("#raw_info").dynatree({
58
+ checkbox: true,
59
+ selectMode: 3,
60
+ children: organizations,
61
+ onSelect: function(select, node) {
62
+ // Get a list of all selected nodes, and convert to a key array:
63
+ var rawInfo = {organizations: [], features: []};
64
+ organizationNames = [];
65
+ $.each(node.tree.getSelectedNodes(), function(index, node){
66
+ if(node.data.key.organization_name && organizationNames.indexOf(node.data.key.organization_name) == -1){
67
+ organizationNames.push(node.data.key.organization_name);
68
+ }
69
+ if(node.data.key.feature_name){
70
+ rawInfo.features.push({organization_id: organizationNames.indexOf(node.data.key.organization_name)+1, name: node.data.key.feature_name});
71
+ }
72
+ });
73
+ $.each(organizationNames, function(index, name){
74
+ rawInfo.organizations.push({id: index+1, name: name});
75
+ });
76
+ $('#raw_info_json')[0].value = JSON.stringify(rawInfo);
77
+
78
+ },
79
+ onDblClick: function(node, event) {
80
+ node.toggleSelect();
81
+ },
82
+ onKeydown: function(node, event) {
83
+ if( event.which == 32 ) {
84
+ node.toggleSelect();
85
+ return false;
86
+ }
87
+ },
88
+ });
89
+ });
90
+ </script>
91
+ HTML
92
+ options.fields.each do |field|
93
+ form.text_field field.to_s.capitalize.gsub("_", " "), field.to_s
94
+ end
95
+ form.html "<input type='hidden' id='raw_info_json' name='raw_info_json' />"
96
+ form.html "<h3>Features</h3>"
97
+ form.html "<div id='raw_info'></div>"
98
+ form.button "Sign In"
99
+ form.to_response
100
+ end
101
+
102
+ uid do
103
+ request.params[options.uid_field.to_s]
104
+ end
105
+
106
+ info do
107
+ options.fields.inject({}) do |hash, field|
108
+ hash[field] = request.params[field.to_s]
109
+ hash
110
+ end.merge(
111
+ :organizations => raw_info['organizations'],
112
+ :features => raw_info['features']
113
+ )
114
+ end
115
+
116
+ def raw_info
117
+ @raw_info ||= JSON.parse(request.params['raw_info_json'])
118
+ end
119
+ end
120
+ end
121
+ end
metadata ADDED
@@ -0,0 +1,72 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: auth-transis-client
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.1
5
+ prerelease:
6
+ platform: ruby
7
+ authors:
8
+ - Tim Galeckas
9
+ autorequire:
10
+ bindir: bin
11
+ cert_chain: []
12
+ date: 2012-08-17 00:00:00.000000000 Z
13
+ dependencies:
14
+ - !ruby/object:Gem::Dependency
15
+ name:
16
+ - omniauth
17
+ - omniauth-oauth2
18
+ requirement: !ruby/object:Gem::Requirement
19
+ none: false
20
+ requirements:
21
+ - - ! '>='
22
+ - !ruby/object:Gem::Version
23
+ version: '0'
24
+ type: :runtime
25
+ prerelease: false
26
+ version_requirements: !ruby/object:Gem::Requirement
27
+ none: false
28
+ requirements:
29
+ - - ! '>='
30
+ - !ruby/object:Gem::Version
31
+ version: '0'
32
+ description: This is the client for TransisApps
33
+ email:
34
+ - tim@galeckas.com
35
+ executables: []
36
+ extensions: []
37
+ extra_rdoc_files: []
38
+ files:
39
+ - .gitignore
40
+ - Gemfile
41
+ - LICENSE.txt
42
+ - README.md
43
+ - Rakefile
44
+ - auth-transis-client.gemspec
45
+ - lib/auth-transis-client.rb
46
+ - lib/auth-transis-client/version.rb
47
+ - lib/omni_auth.rb
48
+ homepage: ''
49
+ licenses: []
50
+ post_install_message:
51
+ rdoc_options: []
52
+ require_paths:
53
+ - lib
54
+ required_ruby_version: !ruby/object:Gem::Requirement
55
+ none: false
56
+ requirements:
57
+ - - ! '>='
58
+ - !ruby/object:Gem::Version
59
+ version: '0'
60
+ required_rubygems_version: !ruby/object:Gem::Requirement
61
+ none: false
62
+ requirements:
63
+ - - ! '>='
64
+ - !ruby/object:Gem::Version
65
+ version: '0'
66
+ requirements: []
67
+ rubyforge_project:
68
+ rubygems_version: 1.8.23
69
+ signing_key:
70
+ specification_version: 3
71
+ summary: See the description
72
+ test_files: []