omniauth-jinshuju 0.0.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: 06e0e63bdb6bd2c2655750e6bda8fc63c33db643
4
+ data.tar.gz: 71f1a2ddc46c6d6263528060a591abb95060675f
5
+ SHA512:
6
+ metadata.gz: 946a6fe035f261c3345b2a72683851708b50cd84165525caf6291db07c31c0d836f31fe574b353fb4e939e19139cf0c1c9d85b6ed7e281e9da0c29706dec6937
7
+ data.tar.gz: f97322df303d927debbc883f7d66ccdbbe26c046c2e06bf5f6d5bdf69776b7305eb36a1fabfc7ad1c753ef58f4332d02c4c271f3221769b966f240cdb84e48c4
@@ -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
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,21 @@
1
+ The MIT License (MIT)
2
+
3
+ Copyright (c) 2016 Michael Chen and AdMaster Inc.
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.
@@ -0,0 +1,76 @@
1
+ # OmniAuth::Strategies::Jinshuju
2
+
3
+ OAuth2 Strategy for [Jinshuju](https://jinshuju.net/)
4
+
5
+ ## Installation
6
+
7
+ Add this line to your application's Gemfile:
8
+
9
+
10
+ ```ruby
11
+ gem 'omniauth-jinshuju', git: 'git@github.com:jinshuju/omniauth-jinshuju.git'
12
+ ```
13
+
14
+ And then execute:
15
+
16
+ $ bundle
17
+
18
+ ## Usage
19
+
20
+ You need `client_id` & `client_secret`.
21
+
22
+ Here's an example for adding the middleware to a Rails app in config/initializers/omniauth.rb:
23
+ ```ruby
24
+ Rails.application.config.middleware.use OmniAuth::Builder do
25
+ provider :jinshuju, ENV["JINSHUJU_CLIENT_ID"], ENV["JINSHUJU_CLIENT_SECRET"]
26
+ end
27
+ ```
28
+
29
+ Or If your are using devise add follwing in config/initializers/devise.rb
30
+ ```ruby
31
+ config.omniauth :jinshuju, ENV["JINSHUJU_CLIENT_ID"], ENV["JINSHUJU_CLIENT_SECRET"]
32
+ ```
33
+
34
+ Then add the following to 'config/routes.rb' so the callback routes are defined.
35
+
36
+ ```ruby
37
+ devise_for :users, :controllers => { :omniauth_callbacks => "users/omniauth_callbacks" }
38
+ ```
39
+
40
+ Make sure your model is omniauthable. Generally this is "/app/models/user.rb"
41
+
42
+ ## Sample Auth Hash
43
+ ```ruby
44
+ {
45
+ "provider"=>"jinshuju",
46
+ "uid"=>"123456",
47
+ "info"=> {
48
+ "name"=>"xiaojin",
49
+ "email"=>"user@email.com",
50
+ },
51
+ "extra"=> {
52
+ "raw_info"=> {
53
+ "type"=>"user",
54
+ "id"=>"123456",
55
+ "name"=>"xiaojin",
56
+ "login"=>"user@email.com"
57
+ }
58
+ }
59
+ }
60
+ ```
61
+
62
+ ## Contributing
63
+
64
+ Bug reports and pull requests are welcome. This project is intended to be a safe, welcoming space for collaboration.
65
+
66
+ 1. Fork it
67
+ 2. Create your feature branch (`git checkout -b my-new-feature`)
68
+ 3. Commit your changes along with test cases (`git commit -am 'Add some feature'`)
69
+ 4. If possible squash your commits to one commit if they all belong to same feature.
70
+ 5. Push to the branch (`git push origin my-new-feature`)
71
+ 6. Create new Pull Request.
72
+
73
+
74
+ ## License
75
+
76
+ 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', 'jinshuju')
@@ -0,0 +1 @@
1
+ require File.join('omniauth', 'strategies', 'jinshuju')
@@ -0,0 +1,5 @@
1
+ module OmniAuth
2
+ module Jinshuju
3
+ VERSION = '0.0.1'
4
+ end
5
+ end
@@ -0,0 +1,45 @@
1
+ require 'omniauth-oauth2'
2
+
3
+ module OmniAuth
4
+ module Strategies
5
+ class Jinshuju < OmniAuth::Strategies::OAuth2
6
+
7
+ option :name, 'jinshuju'
8
+
9
+ option :client_options, {
10
+ site: 'https://api.jinshuju.net',
11
+ authorize_url: 'https://account.jinshuju.net/oauth/authorize',
12
+ token_url: 'https://account.jinshuju.net/oauth/token'
13
+ }
14
+
15
+ option :authorize_params, {scope: 'public'}
16
+ option :token_params, {
17
+ parse: :json
18
+ }
19
+
20
+ uid do
21
+ raw_info['id']
22
+ end
23
+
24
+ info do
25
+ {
26
+ nickname: raw_info['nickname'],
27
+ email: raw_info['email']
28
+ }
29
+ end
30
+
31
+ extra do
32
+ {
33
+ :raw_info => raw_info
34
+ }
35
+ end
36
+
37
+ def raw_info
38
+ @raw_info ||= access_token.get('v4/me').parsed
39
+ end
40
+
41
+ end
42
+ end
43
+ end
44
+
45
+ OmniAuth.config.add_camelization 'jinshuju', 'Jinshuju'
@@ -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/jinshuju/version'
5
+
6
+ Gem::Specification.new do |spec|
7
+ spec.name = 'omniauth-jinshuju'
8
+ spec.version = OmniAuth::Jinshuju::VERSION
9
+ spec.authors = ['Michael Chen']
10
+ spec.email = ['michael.chen@admaster.com.cn']
11
+
12
+ spec.summary = %q{Offical Jinshuju OAuth2 strategy for OmniAuth}
13
+ spec.description = %q{Offical Jinshuju OAuth2 strategy for OmniAuth}
14
+ spec.homepage = 'https://github.com/jinshuju/omniauth-jinshuju'
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.3.1'
22
+
23
+ spec.add_development_dependency 'rake', '~> 10.0'
24
+ spec.add_development_dependency 'rspec', '~> 3.4'
25
+ end
@@ -0,0 +1,110 @@
1
+ require 'spec_helper'
2
+ require 'omniauth-jinshuju'
3
+
4
+ describe OmniAuth::Strategies::Jinshuju 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::Jinshuju.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::Jinshuju::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.jinshuju.net')
35
+ end
36
+
37
+ it 'has correct authorize_url' do
38
+ expect(subject.client.options[:authorize_url]).to eq('https://account.jinshuju.net/oauth/authorize')
39
+ end
40
+
41
+ it 'has correct token_url' do
42
+ expect(subject.client.options[:token_url]).to eq('https://account.jinshuju.net/oauth/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/jinshuju/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 :nickname }
69
+ it { expect(subject.info).to have_key :email }
70
+ end
71
+ end
72
+
73
+ describe '#extra' do
74
+ before :each do
75
+ allow(subject).to receive(:raw_info) { { status: 'active' } }
76
+ end
77
+
78
+ it { expect(subject.extra[:raw_info]).to eq({ status: 'active' }) }
79
+ end
80
+
81
+ describe '#raw_info' do
82
+ before :each do
83
+ access_token = double('access token')
84
+ response = double('response', :parsed => { status: 'active' })
85
+ expect(access_token).to receive(:get).with('v4/me').and_return(response)
86
+ allow(subject).to receive(:access_token) { access_token }
87
+ end
88
+
89
+ it 'returns parsed response from access token' do
90
+ expect(subject.send(:raw_info)).to eq({ status: 'active' })
91
+ end
92
+ end
93
+
94
+ describe '#access_token' do
95
+ before :each do
96
+ response = double('access token',
97
+ access_token: 'access_token',
98
+ refresh_token: 'refresh_token',
99
+ expires_in: 3600,
100
+ expires_at: 12345,
101
+ ).as_null_object
102
+ allow(subject).to receive(:access_token) { response }
103
+ end
104
+
105
+ it { expect(subject.access_token.access_token).to eq('access_token') }
106
+ it { expect(subject.access_token.expires_in).to eq(3600) }
107
+ it { expect(subject.access_token.expires_at).to eq(12345) }
108
+ it { expect(subject.access_token.refresh_token).to eq('refresh_token') }
109
+ end
110
+ 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/jinshuju'
metadata ADDED
@@ -0,0 +1,102 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: omniauth-jinshuju
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.1
5
+ platform: ruby
6
+ authors:
7
+ - Michael Chen
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2016-01-21 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.3.1
20
+ type: :runtime
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - "~>"
25
+ - !ruby/object:Gem::Version
26
+ version: 1.3.1
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: Offical Jinshuju OAuth2 strategy for OmniAuth
56
+ email:
57
+ - michael.chen@admaster.com.cn
58
+ executables: []
59
+ extensions: []
60
+ extra_rdoc_files: []
61
+ files:
62
+ - ".codeclimate.yml"
63
+ - ".gitignore"
64
+ - ".rspec"
65
+ - Gemfile
66
+ - LICENSE
67
+ - README.md
68
+ - Rakefile
69
+ - lib/omniauth-jinshuju.rb
70
+ - lib/omniauth/jinshuju.rb
71
+ - lib/omniauth/jinshuju/version.rb
72
+ - lib/omniauth/strategies/jinshuju.rb
73
+ - omniauth-jinshuju.gemspec
74
+ - spec/omniauth/strategies/jinshuju_spec.rb
75
+ - spec/spec_helper.rb
76
+ homepage: https://github.com/jinshuju/omniauth-jinshuju
77
+ licenses:
78
+ - MIT
79
+ metadata: {}
80
+ post_install_message:
81
+ rdoc_options: []
82
+ require_paths:
83
+ - lib
84
+ required_ruby_version: !ruby/object:Gem::Requirement
85
+ requirements:
86
+ - - ">="
87
+ - !ruby/object:Gem::Version
88
+ version: '0'
89
+ required_rubygems_version: !ruby/object:Gem::Requirement
90
+ requirements:
91
+ - - ">="
92
+ - !ruby/object:Gem::Version
93
+ version: '0'
94
+ requirements: []
95
+ rubyforge_project:
96
+ rubygems_version: 2.4.8
97
+ signing_key:
98
+ specification_version: 4
99
+ summary: Offical Jinshuju OAuth2 strategy for OmniAuth
100
+ test_files:
101
+ - spec/omniauth/strategies/jinshuju_spec.rb
102
+ - spec/spec_helper.rb