omnitoken 0.0.1

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: 3ace4482f49697143d37ce315b327c2a84ed71b3
4
+ data.tar.gz: 99e1e737d587e96b9a4ee7519e44df1a0161ff19
5
+ SHA512:
6
+ metadata.gz: 20970c131a123db1d4f48830429703e4fb3b191d770c2b47383a99f60529fc99e0167ba5a7c6e3705020c9af4507d5d07f10f1156ef55d009d44526b7a8ed6c7
7
+ data.tar.gz: 508f29a138b1c193e26658082e036ec4424c7c552441195c6d7adcb01104ea081fc72366776c1085611fa43c259d37124631b9f489adb89534e064ec402100a3
data/CHANGELOG.md ADDED
@@ -0,0 +1,5 @@
1
+ # OmniToken Changelog
2
+
3
+ ## v0.0.1
4
+ * First alphaish release as a gem.
5
+ * Twitter and Facebook are supported.
data/Gemfile ADDED
@@ -0,0 +1,9 @@
1
+ source "http://rubygems.org"
2
+
3
+ gem 'sinatra'
4
+ gem 'haml'
5
+ gem 'omniauth'
6
+
7
+ group :development do
8
+ gem 'rack-test'
9
+ end
data/README.md ADDED
@@ -0,0 +1,70 @@
1
+ # OmniToken
2
+
3
+ ## Introduction
4
+ OmniToken is a handy tool for getting OAuth tokens from multiple providers. It brings up a web page interface which lists the popular "Login with XXX" social buttons and displays the token and other basic information after user finishes the authentication flow.
5
+
6
+ It is a tiny Sinatra-based web application.
7
+
8
+ It heavily relies on [OmniAuth](https://github.com/intridea/omniauth) and its strategies. Theoretically, any OAuth provider can be supported as long as there is a OmniAuth strategy for it. It can be easily achieved by installing the startegy gem and adding a config file.
9
+
10
+ ## Get Started
11
+ To install the latest stable version, run:
12
+
13
+ `gem install omnitoken`
14
+
15
+ After the gem and its dependencies are installed, run:
16
+
17
+ `omnitoken -s`
18
+
19
+ A web server is started. Visit `http://localhost:4567` in the web browser and you will see a page with the "No OAuth providers are configured." message.
20
+
21
+ Follow next section to add some providers. You need to restart the web server after adding new providers.
22
+
23
+ ## Add Providers
24
+ To get the token from a provider, a tiny configuration file is required. OmniToken has been tested with following providers and a configuration template is shipped for each of them:
25
+ * Twitter
26
+ * Facebook
27
+
28
+ ### Twitter
29
+ First, install the twitter strategy gem:
30
+
31
+ `gem install omniauth-twitter`
32
+
33
+ Copy the twitter template by running:
34
+
35
+ `omnitoken -a twitter`
36
+
37
+ A `twitter.yml` file will be created in `providers` folder in your working directory. Open it using your favorite editor and fill the fileds. The values can be found on your twitter application page you registered beforehand.
38
+
39
+ ### Facebook
40
+ First, install the facebook strategy gem:
41
+
42
+ `gem install omniauth-facebook`
43
+
44
+ Copy the facebook template by running:
45
+
46
+ `omnitoken -a facebook`
47
+
48
+ A `facebook.yml` file will be created in `providers` folder in your working directory. Open it using your favorite editor and fill the fileds. The values can be found on your facebook application page you registered beforehand.
49
+
50
+ ### Others
51
+ Theoretically, OmniToken can be support any provider as long as there is a OmniAuth strategy for it. Please follow these steps to add a provider which doesn't have a shipped template.
52
+
53
+ First, find and install the strategy gem for your provider. Assume it is `omniauth-example`.
54
+
55
+ `gem install omniauth-example`
56
+
57
+ Create a file named `example.ym` and put it in `providers` folder under your working directory. **NOTE: all providers configuration file should be put in `providers`.**
58
+
59
+ Refer to startegies' documentation and get the required argumements. Add a corresponding value to each argument. For example, the arguments are `foo` and `bar`. The `example.yml` should look like this:
60
+
61
+ ```yaml
62
+ foo: "xxx"
63
+ bar: "xxx"
64
+ ```
65
+
66
+ ## Supported Ruby Versions
67
+ OmniToken is tested under 2.0.0.
68
+
69
+ ## License
70
+ Copyright (c) 2013-2014 Minjie Zha. See [LICENSE](https://github.com/magic003/omnitoken/blob/master/LICENSE-MIT) for details.
data/Rakefile ADDED
@@ -0,0 +1,10 @@
1
+ require 'rake'
2
+ require 'rake/testtask'
3
+
4
+ task :default => [:test]
5
+
6
+ desc "Run unit tests"
7
+ Rake::TestTask.new("test") do |t|
8
+ t.pattern = 'test/**/*_test.rb'
9
+ t.verbose = true
10
+ end
data/bin/omnitoken ADDED
@@ -0,0 +1,103 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ # This is the script for running OmniToken application.
4
+ #
5
+ # Usage:
6
+ # omnitoken [options]
7
+ # Options:
8
+ # -a, --add name1,name2,nameN
9
+ # Add the config template for specified OAuth providers
10
+ # -s, --server Start the web server
11
+ # -h, --help Display this help message
12
+ # -v, --version Show OmniToken version
13
+ #
14
+ # Author:: Minjie Zha (mailto:minjiezha@gmail.com)
15
+ # Copyright:: Copyright (c) 2013-2014 Minjie Zha
16
+
17
+ require 'optparse'
18
+
19
+ begin
20
+ require 'omnitoken_app'
21
+ rescue LoadError
22
+ require File.join(File.expand_path(File.dirname(__FILE__)), *%w[.. omnitoken_app])
23
+ end
24
+
25
+ # Add provider templates.
26
+ def on_add(names)
27
+ return if names.nil?
28
+ provider_dir = OmniTokenApp::PROVIDER_DIR
29
+ # create the providers folder if it doesn't exist
30
+ unless names.empty? || Dir.exists?(provider_dir)
31
+ $stdout.puts "Creating #{provider_dir} folder"
32
+ Dir.mkdir(provider_dir)
33
+ end
34
+
35
+ template_dir = File.join(
36
+ File.expand_path(File.dirname(__FILE__)),
37
+ *%w[.. templates])
38
+ names.each do |n|
39
+ file = "#{n.downcase}.yml"
40
+ # check if the template file is available
41
+ unless File.exists?(File.join(template_dir, file))
42
+ $stderr.puts "Template for #{n} is not available. "\
43
+ "Please follow the OmniToken README to create its config file."
44
+ next
45
+ end
46
+
47
+ # check if the config file is already there
48
+ if File.exists?(File.join(provider_dir, file))
49
+ overwrite = loop do
50
+ $stdout.print("File #{file} already exists. Overwrite it?(y/Y/n/N):")
51
+ ans = $stdin.gets.chomp
52
+ break true if 'y'.eql?(ans.downcase)
53
+ break false if 'n'.eql?(ans.downcase)
54
+ end
55
+ next unless overwrite
56
+ end
57
+
58
+ # copy the template file
59
+ $stdout.puts "Copying template #{file}"
60
+ FileUtils.cp(File.join(template_dir, file),
61
+ File.join(provider_dir, ''))
62
+ end
63
+ end
64
+
65
+ # Starts the web server.
66
+ def on_server()
67
+ puts 'Starting OmniToken web server'
68
+ OmniTokenApp.run!
69
+ end
70
+
71
+ OptionParser.new do |opts|
72
+ opts.banner = "Usage: omnitoken [options]"
73
+
74
+ opts.separator ""
75
+ opts.separator "Options:"
76
+
77
+ opts.on('-a', '--add name1,name2,nameN', Array, 'Add the config template for specified OAuth providers') do |names|
78
+ on_add(names)
79
+ exit
80
+ end
81
+
82
+ opts.on('-s', '--server', 'Start the web server') do
83
+ on_server()
84
+ exit
85
+ end
86
+
87
+ opts.on_tail('-h', '--help', 'Display this help message') do
88
+ puts opts
89
+ exit
90
+ end
91
+
92
+ opts.on_tail('-v', '--version', 'Show OmniToken version') do
93
+ puts OmniTokenApp::VERSION
94
+ exit
95
+ end
96
+
97
+ opts.on() do
98
+ puts opts
99
+ exit
100
+ end
101
+
102
+ end.parse!
103
+
data/config.ru ADDED
@@ -0,0 +1,3 @@
1
+ puts $:
2
+ require File.dirname(__FILE__) + '/omnitoken_app'
3
+ run OmniTokenApp
data/omnitoken_app.rb ADDED
@@ -0,0 +1,124 @@
1
+ require 'sinatra/base'
2
+ require 'haml'
3
+ require 'omniauth'
4
+
5
+ require 'yaml'
6
+
7
+ # This is the Sinatra application for getting tokens.
8
+ class OmniTokenApp < Sinatra::Base
9
+ # version number
10
+ VERSION = '0.0.1'
11
+
12
+ # configuration folder for various OAuth providers
13
+ PROVIDER_DIR = 'providers'
14
+
15
+ enable :sessions
16
+ set :haml, {:format => :html5, :layout => :layout}
17
+
18
+ before '/*' do
19
+ # load providers and save in the application level
20
+ if !settings.respond_to?(:providers) || settings.providers.nil?
21
+ load_providers()
22
+ self.class.set :providers, @providers
23
+ else
24
+ @providers = settings.providers
25
+ end
26
+ end
27
+
28
+ # home page
29
+ get '/' do
30
+ haml :index
31
+ end
32
+
33
+ # callback route for providers
34
+ get "#{OmniAuth.config.path_prefix}/:provider/callback" do |p|
35
+ auth = env['omniauth.auth']
36
+ provider = get_provider(p)
37
+ not_found if provider.nil?
38
+ # get the arguments and provided values for the provider
39
+ args = {}
40
+ p_args = provider[:args].dup
41
+ provider[:klass].args.each do |arg|
42
+ args[arg] = p_args.shift
43
+ end
44
+ haml :results, :locals => { auth: env['omniauth.auth'], args: args}
45
+ end
46
+
47
+ # OAuth failure route
48
+ get "#{OmniAuth.config.path_prefix}/failure" do
49
+ [400, haml(:error, :locals => { message: params[:message] })]
50
+ end
51
+
52
+ not_found do
53
+ [404, haml(:error, :locals => { message: "Page Not Found" })]
54
+ end
55
+
56
+
57
+ private
58
+
59
+ # Gets the loaded provider by name
60
+ def get_provider(name)
61
+ provider = nil
62
+ @providers.each do |p|
63
+ provider = p if p[:id].eql?(name.to_sym)
64
+ end
65
+ provider
66
+ end
67
+
68
+ # Loads providers from the configuration files
69
+ def load_providers
70
+ @providers = []
71
+ Dir.glob(File.join(PROVIDER_DIR, '*.yml')) do |file|
72
+ name = File.basename(file, '.yml').to_sym
73
+ # require ruby files for the strategy
74
+ strategy = require_strategy(name)
75
+ @providers << { id: name,
76
+ display_name: OmniAuth::Utils.camelize(name),
77
+ path: "#{OmniAuth.config.path_prefix}/#{name}",
78
+ args: read_strategy_arg(strategy, file),
79
+ klass: strategy
80
+ }
81
+ end
82
+
83
+ # set the strategies as a middleware
84
+ use_strategy_middleware
85
+ end
86
+
87
+ # Sets the OmniAuth builder as a middleware
88
+ def use_strategy_middleware
89
+ providers = @providers
90
+ self.class.use OmniAuth::Builder do
91
+ providers.each do |p|
92
+ provider p[:id], *p[:args]
93
+ end
94
+ end
95
+ end
96
+
97
+ # Reads the arguments for a strategy from the configuration file.
98
+ def read_strategy_arg(strategy, file)
99
+ args = []
100
+ yaml = YAML::load(File.open(file))
101
+ strategy.args.each do |arg|
102
+ if yaml[arg.to_s].nil?
103
+ fail "The #{arg} argument is not provided in #{file}."
104
+ else
105
+ args << yaml[arg.to_s]
106
+ end
107
+ end
108
+ args
109
+ end
110
+
111
+ # Requires the ruby file for a strategy.
112
+ def require_strategy(name)
113
+ begin
114
+ require "omniauth-#{name}"
115
+ OmniAuth::Strategies.const_get(OmniAuth::Utils.camelize(name))
116
+ rescue LoadError => e
117
+ fail e, "Could not find matching strategy for #{name}. You may need to install an additional gem (such as omniauth-#{name})."
118
+ end
119
+ end
120
+
121
+ # Run this application
122
+ run! if app_file == $0
123
+
124
+ end
data/public/style.css ADDED
@@ -0,0 +1,146 @@
1
+ /* global */
2
+ body {
3
+ font-family: Helvetica, Arial, sans-serif;
4
+ color: #333333;
5
+ font-size: 14px;
6
+ line-height: 1.5;
7
+ background: none repeat scroll 0 0 #F9F9F9;
8
+ }
9
+
10
+ h1 {
11
+ font-size: 80px;
12
+ line-height: 1.15;
13
+ }
14
+
15
+ h2 {
16
+ font-size: 2em;
17
+ line-height: 1.15;
18
+ }
19
+
20
+ a {
21
+ text-decoration: none;
22
+ }
23
+
24
+ /* layout */
25
+ #container {
26
+ margin: 0 auto;
27
+ }
28
+
29
+ /* the social buttons styles are copied from https://grove.io/login */
30
+ #social_buttons {
31
+ width: 460px;
32
+ background: none repeat scroll 0 0 white;
33
+ border-radius: 5px 5px 5px 5px;
34
+ box-shadow: 0 1px 5px rgba(0, 0, 0, 0.2);
35
+ margin: 40px auto 20px;
36
+ padding: 30px;
37
+ }
38
+
39
+ #social_buttons h2 {
40
+ border-bottom: 1px solid #F0F0F0;
41
+ margin-bottom: 20px;
42
+ margin-top: 0;
43
+ padding-bottom: 10px
44
+ }
45
+
46
+ #social_buttons ul {
47
+ text-align: center;
48
+ list-style: none outside none;
49
+ margin: 5px;
50
+ padding: 5px;
51
+ }
52
+
53
+ #social_buttons li {
54
+ margin: 20px;
55
+ padding-bottom: 15px;
56
+ }
57
+
58
+ /* This button style is copied from bitbucket's Create repository button */
59
+ .connect_button, .connect_buton:visited {
60
+ font-size: 16px;
61
+ -moz-box-sizing: border-box;
62
+ background: linear-gradient(to bottom, #FFFFFF 0%, #F2F2F2 100%) repeat scroll 0 0 transparent;
63
+ border: 1px solid #CCCCCC;
64
+ border-radius: 3.01px 3.01px 3.01px 3.01px;
65
+ color: #333333;
66
+ cursor: pointer;
67
+ display: inline-block;
68
+ padding: 4px 20px;
69
+ text-decoration: none;
70
+ text-shadow: 0 1px 0 white;
71
+ vertical-align: baseline;
72
+ white-space: nowrap;
73
+ box-shadow: 0 2px 4px rgba(0, 0, 0, 0.2);
74
+ width: 200px;
75
+ }
76
+
77
+ .connect_button:hover {
78
+ background: linear-gradient(to bottom, #FFFFFF 0%, #F7F7F7 100%) repeat scroll 0 0 transparent;
79
+ border-color: #999999;
80
+ color: #000000;
81
+ text-decoration: none;
82
+ }
83
+
84
+ .connect_button:active {
85
+ background-color: #F2F2F2;
86
+ background-image: none;
87
+ box-shadow: 0 3px 6px rgba(0, 0, 0, 0.1) inset;
88
+ text-decoration: none;
89
+ text-shadow: none;
90
+ }
91
+
92
+ .connect_button em {
93
+ font-style: normal;
94
+ font-weight: bold;
95
+ }
96
+
97
+ #error {
98
+ text-align: center;
99
+ margin: 40px auto 20px;
100
+ padding: 30px;
101
+ }
102
+
103
+ #error p {
104
+ font-size: 20px;
105
+ font-style: bold;
106
+ }
107
+
108
+ #results {
109
+ width: 660px;
110
+ background: none repeat scroll 0 0 white;
111
+ border-radius: 5px 5px 5px 5px;
112
+ box-shadow: 0 1px 5px rgba(0, 0, 0, 0.2);
113
+ margin: 40px auto 20px;
114
+ padding: 30px;
115
+ }
116
+
117
+ #results h2 {
118
+ border-bottom: 1px solid #F0F0F0;
119
+ margin-bottom: 20px;
120
+ margin-top: 0;
121
+ padding-bottom: 10px
122
+ }
123
+
124
+ #results table {
125
+ width: 100%;
126
+ border-spacing: 0;
127
+ table-layout: fixed;
128
+ }
129
+
130
+ #results td {
131
+ padding: 8px 0;
132
+ border-bottom: 1px solid #F0F0F0;
133
+ word-wrap: break-word;
134
+ }
135
+
136
+ #results td:first-child {
137
+ width: 30%;
138
+ }
139
+
140
+ #results tr:hover td {
141
+ background: none repeat scroll 0 0 #F8F8F8;
142
+ }
143
+
144
+ #results a {
145
+ float: right;
146
+ }
@@ -0,0 +1,2 @@
1
+ client_id: "CLIENT_ID"
2
+ client_secret: "CLIENT_SECRET"
@@ -0,0 +1,2 @@
1
+ consumer_key: "CONSUMER_KEY"
2
+ consumer_secret: "CONSUMER_SECRET"
data/test/helper.rb ADDED
@@ -0,0 +1,10 @@
1
+ ENV['RACK_ENV'] = 'test'
2
+ require 'minitest/autorun'
3
+ require 'rack/test'
4
+
5
+ begin
6
+ require 'omnitoken_app'
7
+ rescue LoadError
8
+ require File.join(File.expand_path(File.dirname(__FILE__)), %w{.. omnitoken_app})
9
+ end
10
+
@@ -0,0 +1,14 @@
1
+ require File.expand_path(File.dirname(__FILE__)) + '/helper'
2
+
3
+ include Rack::Test::Methods
4
+
5
+ def app
6
+ OmniTokenApp
7
+ end
8
+
9
+ describe 'OmniToken app' do
10
+ it "should show the home page" do
11
+ get '/'
12
+ assert_equal 200, last_response.status
13
+ end
14
+ end
data/views/error.haml ADDED
@@ -0,0 +1,3 @@
1
+ #error
2
+ %h1 Oops!
3
+ %p= message
data/views/index.haml ADDED
@@ -0,0 +1,11 @@
1
+ #social_buttons
2
+ %h2 OmniToken
3
+ - if @providers.nil? || @providers.empty?
4
+ No OAuth providers are configured.
5
+ - else
6
+ %ul
7
+ - @providers.each do |p|
8
+ %li
9
+ %a.connect_button{title: "Login with #{p[:display_name]}", href: "#{p[:path]}"}
10
+ Login with
11
+ %em= p[:display_name]
data/views/layout.haml ADDED
@@ -0,0 +1,10 @@
1
+ !!! 5
2
+ %html{lang: 'en'}
3
+ %head
4
+ %meta{charset: 'utf-8'}
5
+ %title OmniToken
6
+ %link{rel: 'stylesheet', href: '/style.css'}
7
+ %body
8
+ #container
9
+ = yield
10
+
@@ -0,0 +1,18 @@
1
+ #results
2
+ %h2= auth.provider.capitalize
3
+ %table
4
+ %tr
5
+ %td.attr Uid
6
+ %td= auth.uid
7
+ - auth.credentials.each do |key, value|
8
+ %tr
9
+ %td.attr= key.capitalize
10
+ %td= value
11
+ %tr
12
+ %td.attr Name
13
+ %td= auth.info.name
14
+ - args.each do |key, value|
15
+ %tr
16
+ %td.attr= key.capitalize
17
+ %td= value
18
+ %a{title: 'Home', href: '/'} << Back to Home
metadata ADDED
@@ -0,0 +1,119 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: omnitoken
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.1
5
+ platform: ruby
6
+ authors:
7
+ - Minjie Zha
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2013-07-14 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: sinatra
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - '>='
18
+ - !ruby/object:Gem::Version
19
+ version: '0'
20
+ type: :runtime
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - '>='
25
+ - !ruby/object:Gem::Version
26
+ version: '0'
27
+ - !ruby/object:Gem::Dependency
28
+ name: haml
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - '>='
32
+ - !ruby/object:Gem::Version
33
+ version: '0'
34
+ type: :runtime
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - '>='
39
+ - !ruby/object:Gem::Version
40
+ version: '0'
41
+ - !ruby/object:Gem::Dependency
42
+ name: omniauth
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
+ - !ruby/object:Gem::Dependency
56
+ name: rack-test
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - '>='
60
+ - !ruby/object:Gem::Version
61
+ version: '0'
62
+ type: :development
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - '>='
67
+ - !ruby/object:Gem::Version
68
+ version: '0'
69
+ description: OmniToken is a handy tool for getting OAuth tokens from multiple providers.
70
+ email:
71
+ - minjiezha@gmail.com
72
+ executables:
73
+ - omnitoken
74
+ extensions: []
75
+ extra_rdoc_files: []
76
+ files:
77
+ - Rakefile
78
+ - bin/omnitoken
79
+ - config.ru
80
+ - omnitoken_app.rb
81
+ - public/style.css
82
+ - templates/twitter.yml
83
+ - templates/facebook.yml
84
+ - views/error.haml
85
+ - views/layout.haml
86
+ - views/results.haml
87
+ - views/index.haml
88
+ - test/helper.rb
89
+ - test/omnitoken_app_test.rb
90
+ - README.md
91
+ - Gemfile
92
+ - CHANGELOG.md
93
+ homepage: https://github.com/magic003/omnitoken
94
+ licenses:
95
+ - MIT
96
+ metadata: {}
97
+ post_install_message:
98
+ rdoc_options: []
99
+ require_paths:
100
+ - lib
101
+ required_ruby_version: !ruby/object:Gem::Requirement
102
+ requirements:
103
+ - - '>='
104
+ - !ruby/object:Gem::Version
105
+ version: '0'
106
+ required_rubygems_version: !ruby/object:Gem::Requirement
107
+ requirements:
108
+ - - '>='
109
+ - !ruby/object:Gem::Version
110
+ version: '0'
111
+ requirements: []
112
+ rubyforge_project:
113
+ rubygems_version: 2.0.3
114
+ signing_key:
115
+ specification_version: 4
116
+ summary: OmniToken
117
+ test_files:
118
+ - test/helper.rb
119
+ - test/omnitoken_app_test.rb