omniauth-centro 0.0.1

Sign up to get free protection for your applications and to get access to all the features.
data/.gitignore ADDED
@@ -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/README.md ADDED
@@ -0,0 +1,4 @@
1
+ omniauth-centro
2
+ ===============
3
+
4
+ OmniAuth strategy for Centro
@@ -0,0 +1,127 @@
1
+ module OmniAuth
2
+ module Strategies
3
+ class Centro < OmniAuth::Strategies::OAuth2
4
+ option :name, :centro
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
+ :current_organization_id => raw_info['current_organization_id'],
16
+ :raw_info => raw_info
17
+ }
18
+ end
19
+
20
+ def request_phase
21
+ redirect client.auth_code.authorize_url({:redirect_uri => callback_url}.merge(authorize_params).merge(request.params))
22
+ end
23
+
24
+ def raw_info
25
+ @raw_info ||= access_token.get('/api/v1/me.json').parsed
26
+ end
27
+ end
28
+
29
+ class CentroDeveloper
30
+ include OmniAuth::Strategy
31
+ option :name, :centro_developer
32
+
33
+ option :fields, [:email]
34
+ option :uid_field, :email
35
+
36
+ def request_phase
37
+ form = OmniAuth::Form.new(:title => "Centro Developer Login", :url => callback_path, :header_info => <<-HTML)
38
+ <script src="//ajax.googleapis.com/ajax/libs/jquery/1.8.0/jquery.min.js"></script>
39
+ <script src="//ajax.googleapis.com/ajax/libs/jqueryui/1.8.23/jquery-ui.min.js"></script>
40
+
41
+ <link href="http://wwwendt.de/tech/dynatree/src/skin/ui.dynatree.css" rel="stylesheet" type="text/css">
42
+ <script src="http://wwwendt.de/tech/dynatree/src/jquery.dynatree.js" type="text/javascript"></script>
43
+ <script type="text/javascript">
44
+ var updateRawInfoJsonFromTree = function(tree){
45
+ var rawInfo = {organizations: [], features: []};
46
+ organizationNames = [];
47
+ $.each(tree.getSelectedNodes(), function(index, node){
48
+ if(node.data.key.organization_name){
49
+ rawInfo.organizations.push({id: node.data.key.organization_id, name: node.data.key.organization_name});
50
+ }else if(node.data.key.feature_name){
51
+ rawInfo.features.push({organization_id: organizationNames.indexOf(node.data.key.organization_name)+1, name: node.data.key.feature_name});
52
+ }
53
+ });
54
+ $.each(organizationNames, function(index, name){
55
+ });
56
+ $('#raw_info_json')[0].value = JSON.stringify(rawInfo);
57
+ }
58
+ $(function(){
59
+ var feature = function(organization_id, organization_name, feature_name, selected){
60
+ return {title: feature_name, key: {organization_id: organization_id, organization_name: organization_name, feature_name: feature_name}, select: selected};
61
+ }
62
+ var organization = function(id, name, selected){
63
+ return {id: id, title: name, expand: true, key: name, children: [
64
+ feature(id, name,'admin',selected),
65
+ feature(id, name,'media_plan_creation',selected),
66
+ feature(id, name,'media_plan_negotiation',selected),
67
+ feature(id, name,'media_plan_analysis',selected),
68
+ feature(id, name,'finance',selected)
69
+ ]
70
+ }
71
+ }
72
+ var organizations = [
73
+ organization(1, 'Centro',true),
74
+ organization(2, 'CentroTestAgency',false),
75
+ organization(3, 'CentroTestPublisher',false),
76
+ ];
77
+ $("#raw_info").dynatree({
78
+ checkbox: true,
79
+ selectMode: 3,
80
+ children: organizations,
81
+ onSelect: function(select, node) {
82
+ updateRawInfoJsonFromTree(node.tree);
83
+ },
84
+ onDblClick: function(node, event) {
85
+ node.toggleSelect();
86
+ },
87
+ onKeydown: function(node, event) {
88
+ if( event.which == 32 ) {
89
+ node.toggleSelect();
90
+ return false;
91
+ }
92
+ },
93
+ });
94
+ updateRawInfoJsonFromTree($('#raw_info').dynatree('getRoot').tree);
95
+ });
96
+ </script>
97
+ HTML
98
+ options.fields.each do |field|
99
+ form.text_field field.to_s.capitalize.gsub("_", " "), field.to_s
100
+ end
101
+ form.html "<input type='hidden' id='raw_info_json' name='raw_info_json' />"
102
+ form.html "<h3>Features</h3>"
103
+ form.html "<div id='raw_info'></div>"
104
+ form.button "Sign In"
105
+ form.to_response
106
+ end
107
+
108
+ uid do
109
+ request.params[options.uid_field.to_s]
110
+ end
111
+
112
+ info do
113
+ options.fields.inject({}) do |hash, field|
114
+ hash[field] = request.params[field.to_s]
115
+ hash
116
+ end.merge(
117
+ :organizations => raw_info['organizations'],
118
+ :features => raw_info['features']
119
+ )
120
+ end
121
+
122
+ def raw_info
123
+ @raw_info ||= JSON.parse(request.params['raw_info_json'])
124
+ end
125
+ end
126
+ end
127
+ end
@@ -0,0 +1,5 @@
1
+ module OmniAuth
2
+ module Centro
3
+ VERSION = "0.0.1"
4
+ end
5
+ end
@@ -0,0 +1,3 @@
1
+ require 'omniauth-oauth2'
2
+ require "omniauth-centro/version"
3
+ require 'omniauth/strategies/centro'
@@ -0,0 +1,21 @@
1
+ # -*- encoding: utf-8 -*-
2
+ lib = File.expand_path('../lib', __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require 'omniauth-centro/version'
5
+
6
+ Gem::Specification.new do |gem|
7
+ gem.name = "omniauth-centro"
8
+ gem.version = OmniAuth::Centro::VERSION
9
+ gem.authors = ["Tim Galeckas"]
10
+ gem.email = ["tim@galeckas.com"]
11
+ gem.description = %q{OmniAuth strategy for Centro}
12
+ gem.summary = %q{OmniAuth strategy for Centro}
13
+ gem.homepage = "https://github.com/centro/omniauth-centro"
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'
20
+ gem.add_dependency 'omniauth-oauth2'
21
+ end
metadata ADDED
@@ -0,0 +1,84 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: omniauth-centro
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-10-25 00:00:00.000000000 Z
13
+ dependencies:
14
+ - !ruby/object:Gem::Dependency
15
+ name: omniauth
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: omniauth-oauth2
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: OmniAuth strategy for Centro
47
+ email:
48
+ - tim@galeckas.com
49
+ executables: []
50
+ extensions: []
51
+ extra_rdoc_files: []
52
+ files:
53
+ - .gitignore
54
+ - README.md
55
+ - lib/omniauth-centro.rb
56
+ - lib/omniauth-centro/version.rb
57
+ - lib/omniauth/strategies/centro.rb
58
+ - omniauth-centro.gemspec
59
+ homepage: https://github.com/centro/omniauth-centro
60
+ licenses: []
61
+ post_install_message:
62
+ rdoc_options: []
63
+ require_paths:
64
+ - lib
65
+ required_ruby_version: !ruby/object:Gem::Requirement
66
+ none: false
67
+ requirements:
68
+ - - ! '>='
69
+ - !ruby/object:Gem::Version
70
+ version: '0'
71
+ required_rubygems_version: !ruby/object:Gem::Requirement
72
+ none: false
73
+ requirements:
74
+ - - ! '>='
75
+ - !ruby/object:Gem::Version
76
+ version: '0'
77
+ requirements: []
78
+ rubyforge_project:
79
+ rubygems_version: 1.8.23
80
+ signing_key:
81
+ specification_version: 3
82
+ summary: OmniAuth strategy for Centro
83
+ test_files: []
84
+ has_rdoc: