omniauth-line 0.0.2

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: 6cfd8f7cfafbe33031713ab2c19625e5af28826d
4
+ data.tar.gz: 93e0c11310aaa3f088cdf70ff924cf9503093693
5
+ SHA512:
6
+ metadata.gz: e1f4b1d486370e9cad55433f8bb6410768fbede976db16cf07bd2f9c9e1e12f8a07b12fbf35abc939c8285d4ff5ae9c312bceb1a8eac833e512aa032a0c78ed1
7
+ data.tar.gz: 0e083965d16cf0067c372158f2d4a5147303f3d8f9059856eafb0204cc94b38edb32dba90b71df54411a217d12c87b2364f22904ce0f2aa236c16fde254d84af
data/Gemfile ADDED
@@ -0,0 +1,12 @@
1
+ source 'https://rubygems.org'
2
+
3
+ gemspec
4
+
5
+ gem 'rake'
6
+
7
+ group :test do
8
+ gem 'rspec', '~> 3.2'
9
+ gem 'rack-test'
10
+ gem 'simplecov'
11
+ gem 'webmock'
12
+ end
data/README.md ADDED
@@ -0,0 +1,48 @@
1
+ # OmniAuth Line
2
+
3
+ This gem contains the Line OAuth2 Strategy for OmniAuth.
4
+
5
+ Supports the OAuth 2.0 Web Login. Read the Line developers docs for more details: https://developers.line.me/web-login/integrating-web-login
6
+
7
+ ## Using This Strategy
8
+
9
+ First start by adding this gem to your Gemfile:
10
+
11
+ ```ruby
12
+ gem 'omniauth-line'
13
+ ```
14
+
15
+ Next, tell OmniAuth about this provider. For a Rails app, your `config/initializers/omniauth.rb` file should look like this:
16
+
17
+ ```ruby
18
+ # PROFILE permission required!!
19
+ Rails.application.config.middleware.use OmniAuth::Builder do
20
+ provider :line, "Channel_ID", "Channel_Secret"
21
+ end
22
+ ```
23
+
24
+ ## Authentication Hash
25
+ An example auth hash available in `request.env['omniauth.auth']`:
26
+
27
+ ```ruby
28
+ {
29
+ :provider => "line",
30
+ :uid => "a123b4....",
31
+ :info => {
32
+ :name => "yamada tarou",
33
+ :image => "http://dl.profile.line.naver.jp/xxxxx",
34
+ :description => "breakfast now.",
35
+ },
36
+ :credentials => {
37
+ :token => "a1b2c3d4...", # The OAuth 2.0 access token
38
+ :secret => "abcdef1234"
39
+ },
40
+ :extra => {
41
+ # nil
42
+ }
43
+ }
44
+ ```
45
+
46
+ ## Supported Rubies
47
+
48
+ OmniAuth Line is tested under 2.1.x, 2.2.x.
data/Rakefile ADDED
@@ -0,0 +1,8 @@
1
+ require "bundler/gem_tasks"
2
+ require 'rspec/core/rake_task'
3
+
4
+ desc "Run specs"
5
+ RSpec::Core::RakeTask.new
6
+
7
+ desc 'Default: run specs.'
8
+ task :default => :spec
@@ -0,0 +1,2 @@
1
+ require "omniauth-line/version"
2
+ require 'omniauth/strategies/line'
@@ -0,0 +1,5 @@
1
+ module OmniAuth
2
+ module Line
3
+ VERSION = "0.0.2"
4
+ end
5
+ end
@@ -0,0 +1,39 @@
1
+ require 'omniauth-oauth2'
2
+ require 'json'
3
+
4
+ module OmniAuth
5
+ module Strategies
6
+ class Line < OmniAuth::Strategies::OAuth2
7
+ option :name, 'line'
8
+
9
+ option :client_options, {:site => 'https://access.line.me',
10
+ :authorize_url => '/dialog/oauth/weblogin',
11
+ :token_url => '/v1/oauth/accessToken',
12
+ :proxy => ENV['http_proxy'] ? URI(ENV['http_proxy']) : nil}
13
+
14
+ # host changed
15
+ def callback_phase
16
+ options[:client_options][:site] = 'https://api.line.me'
17
+ super
18
+ end
19
+
20
+ uid { raw_info['mid'] }
21
+
22
+ info do
23
+ {
24
+ name: raw_info['displayName'],
25
+ image: raw_info['pictureUrl'],
26
+ description: raw_info['statusMessage']
27
+ }
28
+ end
29
+
30
+ # Require: Access token with PROFILE permission issued.
31
+ def raw_info
32
+ @raw_info ||= JSON.load(access_token.get('v1/profile').body)
33
+ rescue ::Errno::ETIMEDOUT
34
+ raise ::Timeout::Error
35
+ end
36
+
37
+ end
38
+ end
39
+ end
@@ -0,0 +1,24 @@
1
+ # -*- encoding: utf-8 -*-
2
+ $:.push File.expand_path("../lib", __FILE__)
3
+ require "omniauth-line/version"
4
+
5
+ Gem::Specification.new do |s|
6
+ s.name = "omniauth-line"
7
+ s.version = OmniAuth::Line::VERSION
8
+ s.authors = ["kazasiki"]
9
+ s.email = ["kazasiki@gmail.com"]
10
+ s.homepage = "https://github.com/kazasiki/omniauth-line"
11
+ s.description = %q{OmniAuth strategy for Line}
12
+ s.summary = s.description
13
+ s.license = "MIT"
14
+
15
+ s.files = `git ls-files`.split("\n")
16
+ s.test_files = `git ls-files -- {test,spec,features}/*`.split("\n")
17
+ s.executables = `git ls-files -- bin/*`.split("\n").map{ |f| File.basename(f) }
18
+ s.require_paths = ["lib"]
19
+
20
+ s.add_dependency 'json', '~> 1.3'
21
+ s.add_dependency 'omniauth-oauth2', '~>1.3.1'
22
+ s.add_development_dependency 'bundler', '~> 1.0'
23
+
24
+ end
@@ -0,0 +1,87 @@
1
+ require 'spec_helper'
2
+
3
+ describe OmniAuth::Strategies::Line do
4
+ let(:request) { double('Request', :params => {}, :cookies => {}, :env => {}) }
5
+
6
+ subject do
7
+ args = ['channel_id', 'secret', @options || {}].compact
8
+ OmniAuth::Strategies::Line.new(*args).tap do |strategy|
9
+ allow(strategy).to receive(:request) {
10
+ request
11
+ }
12
+ end
13
+ end
14
+
15
+ describe 'client options' do
16
+ it 'should have correct name' do
17
+ expect(subject.options.name).to eq('line')
18
+ end
19
+
20
+ it 'should have correct site' do
21
+ expect(subject.options.client_options.site).to eq('https://access.line.me')
22
+ end
23
+
24
+ it 'should have correct authorize url' do
25
+ expect(subject.options.client_options.authorize_url).to eq('/dialog/oauth/weblogin')
26
+ end
27
+
28
+ it 'should have correct token url' do
29
+ expect(subject.options.client_options.token_url).to eq('/v1/oauth/accessToken')
30
+ end
31
+ end
32
+
33
+ describe 'uid' do
34
+ before do
35
+ allow(subject).to receive(:raw_info).and_return(raw_info_hash)
36
+ end
37
+
38
+ it 'should returns the uid' do
39
+ expect(subject.uid).to eq(raw_info_hash['mid'])
40
+ end
41
+ end
42
+
43
+ describe 'info' do
44
+ before do
45
+ allow(subject).to receive(:raw_info).and_return(raw_info_hash)
46
+ end
47
+
48
+ it 'should returns the name' do
49
+ expect(subject.info[:name]).to eq(raw_info_hash['displayName'])
50
+ end
51
+
52
+ it 'should returns the image' do
53
+ expect(subject.info[:image]).to eq(raw_info_hash['pictureUrl'])
54
+ end
55
+
56
+ it 'should returns the description' do
57
+ expect(subject.info[:description]).to eq(raw_info_hash['statusMessage'])
58
+ end
59
+ end
60
+
61
+ describe 'request_phase' do
62
+ context 'with no request params set' do
63
+ before do
64
+ allow(subject).to receive(:request).and_return(
65
+ double('Request', {:params => {}})
66
+ )
67
+ allow(subject).to receive(:request_phase).and_return(:whatever)
68
+ end
69
+
70
+ it 'should not break' do
71
+ expect { subject.request_phase }.not_to raise_error
72
+ end
73
+ end
74
+ end
75
+
76
+ end
77
+
78
+ private
79
+
80
+ def raw_info_hash
81
+ {
82
+ 'mid' => 'hoge',
83
+ 'displayName' => 'Foo Bar',
84
+ 'pictureUrl' => 'http://xxx.com/aaa.jpg',
85
+ 'statusMessage' => 'Developer'
86
+ }
87
+ end
@@ -0,0 +1,20 @@
1
+ $:.unshift File.expand_path('..', __FILE__)
2
+ $:.unshift File.expand_path('../../lib', __FILE__)
3
+ require 'simplecov'
4
+ SimpleCov.start do
5
+ minimum_coverage(75.00)
6
+ end
7
+ require 'rspec'
8
+ require 'rack/test'
9
+ require 'webmock/rspec'
10
+ require 'omniauth'
11
+ require 'omniauth-line'
12
+
13
+ RSpec.configure do |config|
14
+ config.include WebMock::API
15
+ config.include Rack::Test::Methods
16
+ config.extend OmniAuth::Test::StrategyMacros, :type => :strategy
17
+ config.expect_with :rspec do |c|
18
+ c.syntax = :expect
19
+ end
20
+ end
metadata ADDED
@@ -0,0 +1,97 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: omniauth-line
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.2
5
+ platform: ruby
6
+ authors:
7
+ - kazasiki
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2015-08-24 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: json
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - "~>"
18
+ - !ruby/object:Gem::Version
19
+ version: '1.3'
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'
27
+ - !ruby/object:Gem::Dependency
28
+ name: omniauth-oauth2
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - "~>"
32
+ - !ruby/object:Gem::Version
33
+ version: 1.3.1
34
+ type: :runtime
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - "~>"
39
+ - !ruby/object:Gem::Version
40
+ version: 1.3.1
41
+ - !ruby/object:Gem::Dependency
42
+ name: bundler
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - "~>"
46
+ - !ruby/object:Gem::Version
47
+ version: '1.0'
48
+ type: :development
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - "~>"
53
+ - !ruby/object:Gem::Version
54
+ version: '1.0'
55
+ description: OmniAuth strategy for Line
56
+ email:
57
+ - kazasiki@gmail.com
58
+ executables: []
59
+ extensions: []
60
+ extra_rdoc_files: []
61
+ files:
62
+ - Gemfile
63
+ - README.md
64
+ - Rakefile
65
+ - lib/omniauth-line.rb
66
+ - lib/omniauth-line/version.rb
67
+ - lib/omniauth/strategies/line.rb
68
+ - omniauth-line.gemspec
69
+ - spec/omniauth/strategies/line_spec.rb
70
+ - spec/spec_helper.rb
71
+ homepage: https://github.com/kazasiki/omniauth-line
72
+ licenses:
73
+ - MIT
74
+ metadata: {}
75
+ post_install_message:
76
+ rdoc_options: []
77
+ require_paths:
78
+ - lib
79
+ required_ruby_version: !ruby/object:Gem::Requirement
80
+ requirements:
81
+ - - ">="
82
+ - !ruby/object:Gem::Version
83
+ version: '0'
84
+ required_rubygems_version: !ruby/object:Gem::Requirement
85
+ requirements:
86
+ - - ">="
87
+ - !ruby/object:Gem::Version
88
+ version: '0'
89
+ requirements: []
90
+ rubyforge_project:
91
+ rubygems_version: 2.2.2
92
+ signing_key:
93
+ specification_version: 4
94
+ summary: OmniAuth strategy for Line
95
+ test_files:
96
+ - spec/omniauth/strategies/line_spec.rb
97
+ - spec/spec_helper.rb