omniauth-box 0.0.1
Sign up to get free protection for your applications and to get access to all the features.
- data/.gitignore +17 -0
- data/Gemfile +4 -0
- data/LICENSE +22 -0
- data/README.md +47 -0
- data/Rakefile +2 -0
- data/examples/sinatra.rb +16 -0
- data/lib/omniauth-box.rb +55 -0
- data/lib/omniauth-box/version.rb +5 -0
- data/omniauth-box.gemspec +20 -0
- metadata +77 -0
data/.gitignore
ADDED
data/Gemfile
ADDED
data/LICENSE
ADDED
@@ -0,0 +1,22 @@
|
|
1
|
+
Copyright (c) 2012 TODO: Write your name
|
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,47 @@
|
|
1
|
+
# OmniAuth Box.net Strategy
|
2
|
+
|
3
|
+
This gem provides a dead simple way to authenticate to Box.net using OmniAuth.
|
4
|
+
|
5
|
+
## Installation
|
6
|
+
|
7
|
+
Add this line to your application's Gemfile:
|
8
|
+
|
9
|
+
```ruby
|
10
|
+
gem 'omniauth-box'
|
11
|
+
```
|
12
|
+
|
13
|
+
## Usage
|
14
|
+
|
15
|
+
First, you will need to [register an application](http://www.box.com/developers/services/new_service_terms) with Box.net and obtain an API key. Once you do that, you can use it like so:
|
16
|
+
|
17
|
+
```ruby
|
18
|
+
use OmniAuth::Builder do
|
19
|
+
provider :box, 'yourapikey'
|
20
|
+
end
|
21
|
+
```
|
22
|
+
|
23
|
+
## Auth Hash Schema
|
24
|
+
|
25
|
+
The following information is provided back to you for this provider:
|
26
|
+
|
27
|
+
```ruby
|
28
|
+
{
|
29
|
+
uid: '12345',
|
30
|
+
info: {
|
31
|
+
nickname: 'login', # may be email
|
32
|
+
email: 'someone@example.com'
|
33
|
+
},
|
34
|
+
credentials: {
|
35
|
+
token: 'thetoken' # can be used to auth to the API
|
36
|
+
},
|
37
|
+
extra: { raw_info: raw_api_response }
|
38
|
+
}
|
39
|
+
```
|
40
|
+
|
41
|
+
## Contributing
|
42
|
+
|
43
|
+
1. Fork it
|
44
|
+
2. Create your feature branch (`git checkout -b my-new-feature`)
|
45
|
+
3. Commit your changes (`git commit -am 'Added some feature'`)
|
46
|
+
4. Push to the branch (`git push origin my-new-feature`)
|
47
|
+
5. Create new Pull Request
|
data/Rakefile
ADDED
data/examples/sinatra.rb
ADDED
@@ -0,0 +1,16 @@
|
|
1
|
+
$:.push File.dirname(__FILE__) + '/../lib'
|
2
|
+
|
3
|
+
require 'omniauth-box'
|
4
|
+
require 'sinatra'
|
5
|
+
|
6
|
+
use Rack::Session::Cookie
|
7
|
+
use OmniAuth::Strategies::Box, ENV['BOX_KEY']
|
8
|
+
|
9
|
+
get '/' do
|
10
|
+
"<a href='/auth/box'>Log in with Box</a>"
|
11
|
+
end
|
12
|
+
|
13
|
+
get '/auth/box/callback' do
|
14
|
+
content_type 'text/plain'
|
15
|
+
request.env['omniauth.auth'].inspect
|
16
|
+
end
|
data/lib/omniauth-box.rb
ADDED
@@ -0,0 +1,55 @@
|
|
1
|
+
require "omniauth-box/version"
|
2
|
+
require 'box-api'
|
3
|
+
require 'omniauth'
|
4
|
+
|
5
|
+
module OmniAuth
|
6
|
+
module Strategies
|
7
|
+
class Box
|
8
|
+
include OmniAuth::Strategy
|
9
|
+
|
10
|
+
args [:api_token]
|
11
|
+
|
12
|
+
option :api_token, nil
|
13
|
+
option :name, 'box'
|
14
|
+
|
15
|
+
attr_accessor :auth_token
|
16
|
+
|
17
|
+
def account
|
18
|
+
::Box::Account.new(options[:api_token])
|
19
|
+
end
|
20
|
+
|
21
|
+
def client
|
22
|
+
client = ::Box::Api.new(options[:api_token])
|
23
|
+
client.set_auth_token(self.auth_token)
|
24
|
+
client
|
25
|
+
end
|
26
|
+
|
27
|
+
def request_phase
|
28
|
+
account.authorize do |authorize_url|
|
29
|
+
return redirect authorize_url
|
30
|
+
end
|
31
|
+
end
|
32
|
+
|
33
|
+
def callback_phase
|
34
|
+
self.auth_token = request.params["auth_token"]
|
35
|
+
super
|
36
|
+
end
|
37
|
+
|
38
|
+
uid{ raw_info['user']['user_id'] }
|
39
|
+
|
40
|
+
info do
|
41
|
+
{
|
42
|
+
:email => raw_info['user']['email'],
|
43
|
+
:nickname => raw_info['user']['login'],
|
44
|
+
}
|
45
|
+
end
|
46
|
+
|
47
|
+
extra{ {:raw_info => raw_info} }
|
48
|
+
credentials{ {:token => self.auth_token} }
|
49
|
+
|
50
|
+
def raw_info
|
51
|
+
@raw_info ||= client.get_account_info
|
52
|
+
end
|
53
|
+
end
|
54
|
+
end
|
55
|
+
end
|
@@ -0,0 +1,20 @@
|
|
1
|
+
# -*- encoding: utf-8 -*-
|
2
|
+
require File.expand_path('../lib/omniauth-box/version', __FILE__)
|
3
|
+
|
4
|
+
Gem::Specification.new do |gem|
|
5
|
+
gem.authors = ["Michael Bleigh"]
|
6
|
+
gem.email = ["michael@intridea.com"]
|
7
|
+
gem.description = %q{OmniAuth strategy for Box.net}
|
8
|
+
gem.summary = %q{OmniAuth strategy for Box.net}
|
9
|
+
gem.homepage = "https://github.com/mbleigh/omniauth-box"
|
10
|
+
|
11
|
+
gem.executables = `git ls-files -- bin/*`.split("\n").map{ |f| File.basename(f) }
|
12
|
+
gem.files = `git ls-files`.split("\n")
|
13
|
+
gem.test_files = `git ls-files -- {test,spec,features}/*`.split("\n")
|
14
|
+
gem.name = "omniauth-box"
|
15
|
+
gem.require_paths = ["lib"]
|
16
|
+
gem.version = OmniAuth::Box::VERSION
|
17
|
+
|
18
|
+
gem.add_dependency 'omniauth', '~> 1.0'
|
19
|
+
gem.add_dependency 'box-api'
|
20
|
+
end
|
metadata
ADDED
@@ -0,0 +1,77 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: omniauth-box
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.0.1
|
5
|
+
prerelease:
|
6
|
+
platform: ruby
|
7
|
+
authors:
|
8
|
+
- Michael Bleigh
|
9
|
+
autorequire:
|
10
|
+
bindir: bin
|
11
|
+
cert_chain: []
|
12
|
+
date: 2012-02-01 00:00:00.000000000 Z
|
13
|
+
dependencies:
|
14
|
+
- !ruby/object:Gem::Dependency
|
15
|
+
name: omniauth
|
16
|
+
requirement: &70166961358640 !ruby/object:Gem::Requirement
|
17
|
+
none: false
|
18
|
+
requirements:
|
19
|
+
- - ~>
|
20
|
+
- !ruby/object:Gem::Version
|
21
|
+
version: '1.0'
|
22
|
+
type: :runtime
|
23
|
+
prerelease: false
|
24
|
+
version_requirements: *70166961358640
|
25
|
+
- !ruby/object:Gem::Dependency
|
26
|
+
name: box-api
|
27
|
+
requirement: &70166961356220 !ruby/object:Gem::Requirement
|
28
|
+
none: false
|
29
|
+
requirements:
|
30
|
+
- - ! '>='
|
31
|
+
- !ruby/object:Gem::Version
|
32
|
+
version: '0'
|
33
|
+
type: :runtime
|
34
|
+
prerelease: false
|
35
|
+
version_requirements: *70166961356220
|
36
|
+
description: OmniAuth strategy for Box.net
|
37
|
+
email:
|
38
|
+
- michael@intridea.com
|
39
|
+
executables: []
|
40
|
+
extensions: []
|
41
|
+
extra_rdoc_files: []
|
42
|
+
files:
|
43
|
+
- .gitignore
|
44
|
+
- Gemfile
|
45
|
+
- LICENSE
|
46
|
+
- README.md
|
47
|
+
- Rakefile
|
48
|
+
- examples/sinatra.rb
|
49
|
+
- lib/omniauth-box.rb
|
50
|
+
- lib/omniauth-box/version.rb
|
51
|
+
- omniauth-box.gemspec
|
52
|
+
homepage: https://github.com/mbleigh/omniauth-box
|
53
|
+
licenses: []
|
54
|
+
post_install_message:
|
55
|
+
rdoc_options: []
|
56
|
+
require_paths:
|
57
|
+
- lib
|
58
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
59
|
+
none: false
|
60
|
+
requirements:
|
61
|
+
- - ! '>='
|
62
|
+
- !ruby/object:Gem::Version
|
63
|
+
version: '0'
|
64
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
65
|
+
none: false
|
66
|
+
requirements:
|
67
|
+
- - ! '>='
|
68
|
+
- !ruby/object:Gem::Version
|
69
|
+
version: '0'
|
70
|
+
requirements: []
|
71
|
+
rubyforge_project:
|
72
|
+
rubygems_version: 1.8.11
|
73
|
+
signing_key:
|
74
|
+
specification_version: 3
|
75
|
+
summary: OmniAuth strategy for Box.net
|
76
|
+
test_files: []
|
77
|
+
has_rdoc:
|