omniauth-box-oauth2 0.1.0

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: 4d6cffcd728b0e80437cb82b951808e8f621ad9c
4
+ data.tar.gz: 8c3729c1402ad5d76354198cd2dd14e5e7cf4cdd
5
+ SHA512:
6
+ metadata.gz: 752385736419fa778008cabc1348167e63f59bf7628f3cf6db22f2dd32fe25a968318dde351aab6b6ed16e2cdf6f0c88e591b1ab66daacea5a1830633ea2e35c
7
+ data.tar.gz: b1db3dcc2963ab1af3fb172054acae6f4b44ca1c4eb59c075cb4fe26599ada09cb327d613729fa8b13e94768e0fb51e677b8a6f2a69a0305c588d20023a82356
@@ -0,0 +1,12 @@
1
+ ---
2
+ engines:
3
+ fixme:
4
+ enabled: true
5
+ rubocop:
6
+ enabled: true
7
+ ratings:
8
+ paths:
9
+ - lib/**/*
10
+ - "**.rb"
11
+ exclude_paths:
12
+ - spec/**/*
@@ -0,0 +1,35 @@
1
+ *.gem
2
+ *.rbc
3
+ /.config
4
+ /coverage/
5
+ /InstalledFiles
6
+ /pkg/
7
+ /spec/reports/
8
+ /test/tmp/
9
+ /test/version_tmp/
10
+ /tmp/
11
+
12
+ ## Specific to RubyMotion:
13
+ .dat*
14
+ .repl_history
15
+ build/
16
+
17
+ ## Documentation cache and generated files:
18
+ /.yardoc/
19
+ /_yardoc/
20
+ /doc/
21
+ /rdoc/
22
+
23
+ ## Environment normalisation:
24
+ /.bundle/
25
+ /vendor/bundle
26
+ /lib/bundler/man/
27
+
28
+ # for a library or gem, you might want to ignore these files since the code is
29
+ # intended to run in multiple environments; otherwise, check them in:
30
+ Gemfile.lock
31
+ .ruby-version
32
+ .ruby-gemset
33
+
34
+ # unless supporting rvm < 1.11.0 or doing something fancy, ignore this:
35
+ .rvmrc
data/.rspec ADDED
@@ -0,0 +1,2 @@
1
+ --format documentation
2
+ --color
@@ -0,0 +1,8 @@
1
+ language: ruby
2
+ rvm:
3
+ - 2.2
4
+ - 2.1
5
+ - 2.0
6
+ - 1.9.3
7
+ before_install:
8
+ - gem install bundler -v 1.10.5
@@ -0,0 +1,13 @@
1
+ # Contributor Code of Conduct
2
+
3
+ As contributors and maintainers of this project, we pledge to respect all people who contribute through reporting issues, posting feature requests, updating documentation, submitting pull requests or patches, and other activities.
4
+
5
+ We are committed to making participation in this project a harassment-free experience for everyone, regardless of level of experience, gender, gender identity and expression, sexual orientation, disability, personal appearance, body size, race, ethnicity, age, or religion.
6
+
7
+ Examples of unacceptable behavior by participants include the use of sexual language or imagery, derogatory comments or personal attacks, trolling, public or private harassment, insults, or other unprofessional conduct.
8
+
9
+ Project maintainers have the right and responsibility to remove, edit, or reject comments, commits, code, wiki edits, issues, and other contributions that are not aligned to this Code of Conduct. Project maintainers who do not follow the Code of Conduct may be removed from the project team.
10
+
11
+ Instances of abusive, harassing, or otherwise unacceptable behavior may be reported by opening an issue or contacting one or more of the project maintainers.
12
+
13
+ This Code of Conduct is adapted from the [Contributor Covenant](http://contributor-covenant.org), version 1.0.0, available at [http://contributor-covenant.org/version/1/0/0/](http://contributor-covenant.org/version/1/0/0/)
data/Gemfile ADDED
@@ -0,0 +1,7 @@
1
+ source 'https://rubygems.org'
2
+
3
+ gemspec
4
+
5
+ group :test do
6
+ gem 'codeclimate-test-reporter'
7
+ end
data/LICENSE ADDED
@@ -0,0 +1,22 @@
1
+ The MIT License (MIT)
2
+
3
+ Copyright (c) 2016 Pramod Shinde
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
22
+
@@ -0,0 +1,108 @@
1
+ [![Gem Version](https://badge.fury.io/rb/omniauth-box-oauth2.svg)](https://badge.fury.io/rb/omniauth-box-oauth2)
2
+ [![Build Status](https://travis-ci.org/pramodshinde/omniauth-box-oauth2.svg?branch=master)](https://travis-ci.org/pramodshinde/omniauth-box-oauth2)
3
+ [![Code Climate](https://codeclimate.com/github/pramodshinde/omniauth-box-oauth2/badges/gpa.svg)](https://codeclimate.com/github/pramodshinde/omniauth-box-oauth2)
4
+ [![Test Coverage](https://codeclimate.com/github/pramodshinde/omniauth-box-oauth2/badges/coverage.svg)](https://codeclimate.com/github/pramodshinde/omniauth-box-oauth2/coverage)
5
+ [![Dependency Status](https://gemnasium.com/pramodshinde/omniauth-box-oauth2.svg)](https://gemnasium.com/pramodshinde/omniauth-box-oauth2)
6
+
7
+ # OmniAuth::Strategies::BoxOauth2
8
+
9
+ OAuth2 Strategy for [Box](https://www.box.com/)
10
+
11
+ ## Installation
12
+
13
+ Add this line to your application's Gemfile:
14
+
15
+ ```ruby
16
+ gem 'omniauth-box-oauth2'
17
+ ```
18
+
19
+ And then execute:
20
+
21
+ $ bundle
22
+
23
+ Or install it yourself as:
24
+
25
+ $ gem install omniauth-box-oauth2
26
+
27
+ ## Usage
28
+
29
+ You can register your application [here](https://cloud.app.box.com/login) and get `client_id` & `client_secret`.
30
+
31
+ Here's an example for adding the middleware to a Rails app in config/initializers/omniauth.rb:
32
+ ```ruby
33
+ Rails.application.config.middleware.use OmniAuth::Builder do
34
+ provider :box_oauth2, ENV["BOX_CLIENT_ID"], ENV["BOX_CLIENT_SECRET"]
35
+ end
36
+ ```
37
+
38
+ Or If your are using devise add follwing in config/initializers/devise.rb
39
+ ```ruby
40
+ config.omniauth :box_oauth2, ENV["BOX_CLIENT_ID"], ENV["BOX_CLIENT_SECRET"]
41
+ ```
42
+
43
+ Then add the following to 'config/routes.rb' so the callback routes are defined.
44
+
45
+ ```ruby
46
+ devise_for :users, :controllers => { :omniauth_callbacks => "users/omniauth_callbacks" }
47
+ ```
48
+
49
+ Make sure your model is omniauthable. Generally this is "/app/models/user.rb"
50
+
51
+ ## Sample Auth Hash
52
+ ```ruby
53
+ {
54
+ "provider"=>"box_oauth2",
55
+ "uid"=>"123456",
56
+ "info"=> {
57
+ "name"=>"Pramod Shinde",
58
+ "email"=>"box_user@email.com",
59
+ "job_title"=>"Ruby On Rails Developer",
60
+ "image"=>"https://app.box.com/api/avatar/large/123456",
61
+ "phone"=>"1234567890",
62
+ "address"=>"address",
63
+ "status"=>"active"
64
+ },
65
+ "credentials"=> {
66
+ "token"=>"box_access_token",
67
+ "refresh_token"=>"box_refresh_token",
68
+ "expires_at"=>1451681914,
69
+ "expires"=>true
70
+ },
71
+ "extra"=> {
72
+ "raw_info"=> {
73
+ "type"=>"user",
74
+ "id"=>"123456",
75
+ "name"=>"Pramod Shinde",
76
+ "login"=>"box_user@email.com",
77
+ "created_at"=>"2014-10-28T00:04:41-07:00",
78
+ "modified_at"=>"2016-01-01T10:11:16-08:00",
79
+ "language"=>"en",
80
+ "timezone"=>"America/Los_Angeles",
81
+ "space_amount"=>10737418240,
82
+ "space_used"=>301803,
83
+ "max_upload_size"=>2147483648,
84
+ "status"=>"active",
85
+ "job_title"=>"Ruby On Rails Developer",
86
+ "phone"=>"1234567890",
87
+ "address"=>"address",
88
+ "avatar_url"=>"https://app.box.com/api/avatar/large/123456"
89
+ }
90
+ }
91
+ }
92
+ ```
93
+
94
+ ## Contributing
95
+
96
+ Bug reports and pull requests are welcome. This project is intended to be a safe, welcoming space for collaboration, and contributors are expected to adhere to the [Contributor Covenant](contributor-covenant.org) code of conduct.
97
+
98
+ 1. Fork it
99
+ 2. Create your feature branch (`git checkout -b my-new-feature`)
100
+ 3. Commit your changes along with test cases (`git commit -am 'Add some feature'`)
101
+ 4. If possible squash your commits to one commit if they all belong to same feature.
102
+ 5. Push to the branch (`git push origin my-new-feature`)
103
+ 6. Create new Pull Request.
104
+
105
+
106
+ ## License
107
+
108
+ The gem is available as open source under the terms of the [MIT License](http://opensource.org/licenses/MIT).
@@ -0,0 +1,6 @@
1
+ require 'bundler/gem_tasks'
2
+ require 'rspec/core/rake_task'
3
+
4
+ RSpec::Core::RakeTask.new(:spec)
5
+
6
+ task default: :spec
@@ -0,0 +1 @@
1
+ require File.join('omniauth', 'box_oauth2')
@@ -0,0 +1 @@
1
+ require File.join('omniauth', 'strategies', 'box_oauth2')
@@ -0,0 +1,5 @@
1
+ module OmniAuth
2
+ module BoxOauth2
3
+ VERSION = '0.1.0'
4
+ end
5
+ end
@@ -0,0 +1,38 @@
1
+ require 'omniauth-oauth2'
2
+ module OmniAuth
3
+ module Strategies
4
+ class BoxOauth2 < OmniAuth::Strategies::OAuth2
5
+ option :name, 'box_oauth2'
6
+
7
+ option :client_options, {
8
+ site: 'https://api.box.com/2.0/',
9
+ authorize_url: 'https://app.box.com/api/oauth2/authorize',
10
+ token_url: 'https://api.box.com/oauth2/token'
11
+ }
12
+
13
+ uid { raw_info['id'] }
14
+
15
+ info do
16
+ {
17
+ name: raw_info['name'],
18
+ email: raw_info['login'],
19
+ job_title: raw_info['job_title'],
20
+ image: raw_info['avatar_url'],
21
+ phone: raw_info['phone'],
22
+ address: raw_info['address'],
23
+ status: raw_info['status']
24
+ }
25
+ end
26
+
27
+ extra do
28
+ { raw_info: raw_info }
29
+ end
30
+
31
+ private
32
+
33
+ def raw_info
34
+ @raw_info ||= access_token.get('users/me').parsed || {}
35
+ end
36
+ end
37
+ end
38
+ end
@@ -0,0 +1,25 @@
1
+ # coding: utf-8
2
+ lib = File.expand_path('../lib', __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require 'omniauth/box_oauth2/version'
5
+
6
+ Gem::Specification.new do |spec|
7
+ spec.name = 'omniauth-box-oauth2'
8
+ spec.version = OmniAuth::BoxOauth2::VERSION
9
+ spec.authors = ['Pramod Shinde']
10
+ spec.email = ['pramodshinde7@gmail.com']
11
+
12
+ spec.summary = %q{A Box OAuth2 strategy for OmniAuth 1.x}
13
+ spec.description = %q{A Box OAuth2 strategy for OmniAuth 1.x}
14
+ spec.homepage = 'https://github.com/pramodshinde/omniauth-box-oauth2'
15
+ spec.license = 'MIT'
16
+
17
+ spec.files = `git ls-files -z`.split("\x0")
18
+ spec.test_files = `git ls-files -- {test,spec,features}/*`.split("\n")
19
+ spec.require_paths = ['lib']
20
+
21
+ spec.add_runtime_dependency 'omniauth-oauth2', '~> 1.2'
22
+
23
+ spec.add_development_dependency 'rake', '~> 10.0'
24
+ spec.add_development_dependency 'rspec', '~> 3.4'
25
+ end
@@ -0,0 +1,115 @@
1
+ require 'spec_helper'
2
+ require 'omniauth-box-oauth2'
3
+
4
+ describe OmniAuth::Strategies::BoxOauth2 do
5
+ let(:request) { double('Request', :params => {}, :cookies => {}, :env => {}) }
6
+ let(:app) {
7
+ lambda do
8
+ [200, {}, ["Hello."]]
9
+ end
10
+ }
11
+
12
+ subject do
13
+ OmniAuth::Strategies::BoxOauth2.new(app, 'appid', 'secret', @options || {}).tap do |strategy|
14
+ allow(strategy).to receive(:request) {
15
+ request
16
+ }
17
+ end
18
+ end
19
+
20
+ before do
21
+ OmniAuth.config.test_mode = true
22
+ end
23
+
24
+ after do
25
+ OmniAuth.config.test_mode = false
26
+ end
27
+
28
+ it 'has a version number' do
29
+ expect(OmniAuth::BoxOauth2::VERSION).not_to be nil
30
+ end
31
+
32
+ describe '#client_options' do
33
+ it 'has correct site' do
34
+ expect(subject.client.site).to eq('https://api.box.com/2.0/')
35
+ end
36
+
37
+ it 'has correct authorize_url' do
38
+ expect(subject.client.options[:authorize_url]).to eq('https://app.box.com/api/oauth2/authorize')
39
+ end
40
+
41
+ it 'has correct token_url' do
42
+ expect(subject.client.options[:token_url]).to eq('https://api.box.com/oauth2/token')
43
+ end
44
+ end
45
+
46
+ describe '#callback_path' do
47
+ it 'has the correct callback path' do
48
+ expect(subject.callback_path).to eq('/auth/box_oauth2/callback')
49
+ end
50
+ end
51
+
52
+ describe '#uid' do
53
+ before :each do
54
+ allow(subject).to receive(:raw_info) { { 'id' => 'uid' } }
55
+ end
56
+
57
+ it 'returns the id from raw_info' do
58
+ expect(subject.uid).to eq('uid')
59
+ end
60
+ end
61
+
62
+ describe '#info' do
63
+ before :each do
64
+ allow(subject).to receive(:raw_info) { {} }
65
+ end
66
+
67
+ context 'has all the necessary fields' do
68
+ it { expect(subject.info).to have_key :name }
69
+ it { expect(subject.info).to have_key :email }
70
+ it { expect(subject.info).to have_key :job_title }
71
+ it { expect(subject.info).to have_key :phone }
72
+ it { expect(subject.info).to have_key :address }
73
+ it { expect(subject.info).to have_key :status }
74
+ it { expect(subject.info).to have_key :image }
75
+ end
76
+ end
77
+
78
+ describe '#extra' do
79
+ before :each do
80
+ allow(subject).to receive(:raw_info) { { status: 'active' } }
81
+ end
82
+
83
+ it { expect(subject.extra[:raw_info]).to eq({ status: 'active' }) }
84
+ end
85
+
86
+ describe '#raw_info' do
87
+ before :each do
88
+ access_token = double('access token')
89
+ response = double('response', :parsed => { status: 'active' })
90
+ expect(access_token).to receive(:get).with('users/me').and_return(response)
91
+ allow(subject).to receive(:access_token) { access_token }
92
+ end
93
+
94
+ it 'returns parsed response from access token' do
95
+ expect(subject.send(:raw_info)).to eq({ status: 'active' })
96
+ end
97
+ end
98
+
99
+ describe '#access_token' do
100
+ before :each do
101
+ response = double('access token',
102
+ access_token: 'access_token',
103
+ refresh_token: 'refresh_token',
104
+ expires_in: 3600,
105
+ expires_at: 12345,
106
+ ).as_null_object
107
+ allow(subject).to receive(:access_token) { response }
108
+ end
109
+
110
+ it { expect(subject.access_token.access_token).to eq('access_token') }
111
+ it { expect(subject.access_token.expires_in).to eq(3600) }
112
+ it { expect(subject.access_token.expires_at).to eq(12345) }
113
+ it { expect(subject.access_token.refresh_token).to eq('refresh_token') }
114
+ end
115
+ end
@@ -0,0 +1,4 @@
1
+ $LOAD_PATH.unshift File.expand_path('../../lib', __FILE__)
2
+ require 'codeclimate-test-reporter'
3
+ CodeClimate::TestReporter.start
4
+ require 'omniauth/box_oauth2'
metadata ADDED
@@ -0,0 +1,103 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: omniauth-box-oauth2
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.0
5
+ platform: ruby
6
+ authors:
7
+ - Pramod Shinde
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2016-01-06 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: omniauth-oauth2
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - "~>"
18
+ - !ruby/object:Gem::Version
19
+ version: '1.2'
20
+ type: :runtime
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - "~>"
25
+ - !ruby/object:Gem::Version
26
+ version: '1.2'
27
+ - !ruby/object:Gem::Dependency
28
+ name: rake
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - "~>"
32
+ - !ruby/object:Gem::Version
33
+ version: '10.0'
34
+ type: :development
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - "~>"
39
+ - !ruby/object:Gem::Version
40
+ version: '10.0'
41
+ - !ruby/object:Gem::Dependency
42
+ name: rspec
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - "~>"
46
+ - !ruby/object:Gem::Version
47
+ version: '3.4'
48
+ type: :development
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - "~>"
53
+ - !ruby/object:Gem::Version
54
+ version: '3.4'
55
+ description: A Box OAuth2 strategy for OmniAuth 1.x
56
+ email:
57
+ - pramodshinde7@gmail.com
58
+ executables: []
59
+ extensions: []
60
+ extra_rdoc_files: []
61
+ files:
62
+ - ".codeclimate.yml"
63
+ - ".gitignore"
64
+ - ".rspec"
65
+ - ".travis.yml"
66
+ - CODE_OF_CONDUCT.md
67
+ - Gemfile
68
+ - LICENSE
69
+ - README.md
70
+ - Rakefile
71
+ - lib/omniauth-box-oauth2.rb
72
+ - lib/omniauth/box_oauth2.rb
73
+ - lib/omniauth/box_oauth2/version.rb
74
+ - lib/omniauth/strategies/box_oauth2.rb
75
+ - omniauth-box-oauth2.gemspec
76
+ - spec/omniauth/strategies/box_oauth2_spec.rb
77
+ - spec/spec_helper.rb
78
+ homepage: https://github.com/pramodshinde/omniauth-box-oauth2
79
+ licenses:
80
+ - MIT
81
+ metadata: {}
82
+ post_install_message:
83
+ rdoc_options: []
84
+ require_paths:
85
+ - lib
86
+ required_ruby_version: !ruby/object:Gem::Requirement
87
+ requirements:
88
+ - - ">="
89
+ - !ruby/object:Gem::Version
90
+ version: '0'
91
+ required_rubygems_version: !ruby/object:Gem::Requirement
92
+ requirements:
93
+ - - ">="
94
+ - !ruby/object:Gem::Version
95
+ version: '0'
96
+ requirements: []
97
+ rubyforge_project:
98
+ rubygems_version: 2.4.5
99
+ signing_key:
100
+ specification_version: 4
101
+ summary: A Box OAuth2 strategy for OmniAuth 1.x
102
+ test_files: []
103
+ has_rdoc: