omniauth-line-messenger 0.2.0

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.
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA256:
3
+ metadata.gz: 79f8458cb7c4306e51a7cbfdc32ec4c30eb266fea5d622b2a32eb9eef3900e43
4
+ data.tar.gz: 99e30e6dff57b2ecc094a920270ce98ea6dc6ffc8b96255efd0bed7f077cdd7e
5
+ SHA512:
6
+ metadata.gz: 8339b116425c105f62bc2bd1c93a33ec6487885480972542fbe2de3634002cfaa144c253e8fd3d7e76693fdc8b23482353188485521b60e630120a814c629d1c
7
+ data.tar.gz: 92da81f4da46e4ed6d0d268af1af6a7135674f6fef1c71f72432dca71a6be0f6ae047a3a400aecaf58f7022b018513fb62e99ccffe84cb26d98315cb431beaeb
data/.gitignore ADDED
@@ -0,0 +1,3 @@
1
+ /coverage
2
+ /coverage/*
3
+ *.DS_Store
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/Gemfile.lock ADDED
@@ -0,0 +1,95 @@
1
+ PATH
2
+ remote: .
3
+ specs:
4
+ omniauth-line-messenger (0.2.0)
5
+ json (>= 2.3.0)
6
+ omniauth-oauth2 (~> 1.3)
7
+
8
+ GEM
9
+ remote: https://rubygems.org/
10
+ specs:
11
+ addressable (2.8.7)
12
+ public_suffix (>= 2.0.2, < 7.0)
13
+ base64 (0.2.0)
14
+ bigdecimal (3.1.8)
15
+ crack (1.0.0)
16
+ bigdecimal
17
+ rexml
18
+ diff-lcs (1.5.1)
19
+ docile (1.4.1)
20
+ faraday (2.8.1)
21
+ base64
22
+ faraday-net_http (>= 2.0, < 3.1)
23
+ ruby2_keywords (>= 0.0.4)
24
+ faraday-net_http (3.0.2)
25
+ hashdiff (1.1.1)
26
+ hashie (5.0.0)
27
+ json (2.7.2)
28
+ jwt (2.9.0)
29
+ base64
30
+ multi_xml (0.6.0)
31
+ oauth2 (2.0.9)
32
+ faraday (>= 0.17.3, < 3.0)
33
+ jwt (>= 1.0, < 3.0)
34
+ multi_xml (~> 0.5)
35
+ rack (>= 1.2, < 4)
36
+ snaky_hash (~> 2.0)
37
+ version_gem (~> 1.1)
38
+ omniauth (2.1.2)
39
+ hashie (>= 3.4.6)
40
+ rack (>= 2.2.3)
41
+ rack-protection
42
+ omniauth-oauth2 (1.8.0)
43
+ oauth2 (>= 1.4, < 3)
44
+ omniauth (~> 2.0)
45
+ public_suffix (5.1.1)
46
+ rack (3.1.7)
47
+ rack-protection (3.0.6)
48
+ rack
49
+ rack-test (2.1.0)
50
+ rack (>= 1.3)
51
+ rake (13.2.1)
52
+ rexml (3.3.7)
53
+ rspec (3.13.0)
54
+ rspec-core (~> 3.13.0)
55
+ rspec-expectations (~> 3.13.0)
56
+ rspec-mocks (~> 3.13.0)
57
+ rspec-core (3.13.1)
58
+ rspec-support (~> 3.13.0)
59
+ rspec-expectations (3.13.3)
60
+ diff-lcs (>= 1.2.0, < 2.0)
61
+ rspec-support (~> 3.13.0)
62
+ rspec-mocks (3.13.1)
63
+ diff-lcs (>= 1.2.0, < 2.0)
64
+ rspec-support (~> 3.13.0)
65
+ rspec-support (3.13.1)
66
+ ruby2_keywords (0.0.5)
67
+ simplecov (0.22.0)
68
+ docile (~> 1.1)
69
+ simplecov-html (~> 0.11)
70
+ simplecov_json_formatter (~> 0.1)
71
+ simplecov-html (0.13.1)
72
+ simplecov_json_formatter (0.1.4)
73
+ snaky_hash (2.0.1)
74
+ hashie
75
+ version_gem (~> 1.1, >= 1.1.1)
76
+ version_gem (1.1.4)
77
+ webmock (3.23.1)
78
+ addressable (>= 2.8.0)
79
+ crack (>= 0.3.2)
80
+ hashdiff (>= 0.4.0, < 2.0.0)
81
+
82
+ PLATFORMS
83
+ arm64-darwin-22
84
+
85
+ DEPENDENCIES
86
+ bundler (~> 2.0)
87
+ omniauth-line-messenger!
88
+ rack-test
89
+ rake
90
+ rspec (~> 3.2)
91
+ simplecov
92
+ webmock
93
+
94
+ BUNDLED WITH
95
+ 2.4.22
data/README.md ADDED
@@ -0,0 +1,49 @@
1
+ # OmniAuth Line
2
+
3
+ This gem contains the Line OAuth2 Strategy for OmniAuth.
4
+
5
+ Supports the OpenID Connect Web Login. Read the Line developers docs for more details: https://developers.line.me/en/docs/line-login/web/integrate-line-login/
6
+
7
+ ## Using This Strategy
8
+
9
+ First start by adding this gem to your Gemfile:
10
+
11
+ ```ruby
12
+ gem 'omniauth-line-messenger'
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_messenger, "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
+ :email => "foo@bar.com"
36
+ },
37
+ :credentials => {
38
+ :token => "a1b2c3d4...", # The OAuth 2.0 access token
39
+ :secret => "abcdef1234"
40
+ },
41
+ :extra => {
42
+ # nil
43
+ }
44
+ }
45
+ ```
46
+
47
+ ## Supported Rubies
48
+
49
+ 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,54 @@
1
+ require 'omniauth-oauth2'
2
+ require 'json'
3
+
4
+ module OmniAuth
5
+ module Strategies
6
+ class LineMessenger < OmniAuth::Strategies::OAuth2
7
+ option :name, 'line_messenger'
8
+ option :scope, 'profile openid email'
9
+
10
+ option :client_options, {
11
+ site: 'https://access.line.me',
12
+ authorize_url: '/oauth2/v2.1/authorize',
13
+ token_url: '/oauth2/v2.1/token'
14
+ }
15
+
16
+ # host changed
17
+ def callback_phase
18
+ options[:client_options][:site] = 'https://api.line.me'
19
+ super
20
+ end
21
+
22
+ def callback_url
23
+ # Fixes regression in omniauth-oauth2 v1.4.0 by https://github.com/intridea/omniauth-oauth2/commit/85fdbe117c2a4400d001a6368cc359d88f40abc7
24
+ options[:callback_url] || (full_host + script_name + callback_path)
25
+ end
26
+
27
+ uid { raw_info['userId'] }
28
+
29
+ info do
30
+ {
31
+ name: raw_info['displayName'],
32
+ image: raw_info['pictureUrl'],
33
+ description: raw_info['statusMessage'],
34
+ email: fetch_email
35
+ # email: JWT.decode(access_token.params['id_token'], options['client_secret']).first&.dig('email')
36
+ }
37
+ end
38
+
39
+ # Require: Access token with PROFILE permission issued.
40
+ def raw_info
41
+ @raw_info ||= JSON.load(access_token.get('v2/profile').body)
42
+ rescue ::Errno::ETIMEDOUT
43
+ raise ::Timeout::Error
44
+ end
45
+
46
+ def fetch_email
47
+ data = JSON.load(access_token.post('oauth2/v2.1/verify', params: { id_token: access_token.params['id_token'], client_id: options['client_id'] }).body)
48
+ data['email']
49
+ rescue ::Errno::ETIMEDOUT
50
+ raise ::Timeout::Error
51
+ end
52
+ end
53
+ end
54
+ end
@@ -0,0 +1,5 @@
1
+ module OmniAuth
2
+ module LineMessenger
3
+ VERSION = "0.2.0"
4
+ end
5
+ end
@@ -0,0 +1,2 @@
1
+ require "omniauth-line-messenger/version"
2
+ require 'omniauth/strategies/line_messenger'
@@ -0,0 +1,23 @@
1
+ # -*- encoding: utf-8 -*-
2
+ $:.push File.expand_path("../lib", __FILE__)
3
+ require "omniauth-line-messenger/version"
4
+
5
+ Gem::Specification.new do |s|
6
+ s.name = "omniauth-line-messenger"
7
+ s.version = OmniAuth::LineMessenger::VERSION
8
+ s.authors = ["kazasiki", "marsz"]
9
+ s.email = ["marsz330@gmail.com"]
10
+ s.homepage = "https://github.com/marsz/omniauth-line-messenger"
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', '>= 2.3.0'
21
+ s.add_dependency 'omniauth-oauth2', '~>1.3'
22
+ s.add_development_dependency 'bundler', '~> 2.0'
23
+ end
@@ -0,0 +1,89 @@
1
+ require 'spec_helper'
2
+
3
+ describe OmniAuth::Strategies::LineMessenger do
4
+ let(:request) { double('Request', :params => {}, :cookies => {}, :env => {}) }
5
+
6
+ subject do
7
+ args = ['channel_id', 'secret', @options || {}].compact
8
+ OmniAuth::Strategies::LineMessenger.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_messenger')
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('/oauth2/v2.1/authorize')
26
+ end
27
+
28
+ it 'should have correct token url' do
29
+ expect(subject.options.client_options.token_url).to eq('/oauth2/v2.1/token')
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
+ allow(subject).to receive(:fetch_email).and_return('foo@bar.com')
37
+ end
38
+
39
+ it 'should returns the uid' do
40
+ expect(subject.uid).to eq(raw_info_hash['mid'])
41
+ end
42
+ end
43
+
44
+ describe 'info' do
45
+ before do
46
+ allow(subject).to receive(:raw_info).and_return(raw_info_hash)
47
+ allow(subject).to receive(:fetch_email).and_return('foo@bar.com')
48
+ end
49
+
50
+ it 'should returns the name' do
51
+ expect(subject.info[:name]).to eq(raw_info_hash['displayName'])
52
+ end
53
+
54
+ it 'should returns the image' do
55
+ expect(subject.info[:image]).to eq(raw_info_hash['pictureUrl'])
56
+ end
57
+
58
+ it 'should returns the description' do
59
+ expect(subject.info[:description]).to eq(raw_info_hash['statusMessage'])
60
+ end
61
+ end
62
+
63
+ describe 'request_phase' do
64
+ context 'with no request params set' do
65
+ before do
66
+ allow(subject).to receive(:request).and_return(
67
+ double('Request', {:params => {}})
68
+ )
69
+ allow(subject).to receive(:request_phase).and_return(:whatever)
70
+ end
71
+
72
+ it 'should not break' do
73
+ expect { subject.request_phase }.not_to raise_error
74
+ end
75
+ end
76
+ end
77
+
78
+ end
79
+
80
+ private
81
+
82
+ def raw_info_hash
83
+ {
84
+ 'uid' => 'hoge',
85
+ 'displayName' => 'Foo Bar',
86
+ 'pictureUrl' => 'http://xxx.com/aaa.jpg',
87
+ 'statusMessage' => 'Developer'
88
+ }
89
+ 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-messenger'
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,99 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: omniauth-line-messenger
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.2.0
5
+ platform: ruby
6
+ authors:
7
+ - kazasiki
8
+ - marsz
9
+ autorequire:
10
+ bindir: bin
11
+ cert_chain: []
12
+ date: 2024-09-17 00:00:00.000000000 Z
13
+ dependencies:
14
+ - !ruby/object:Gem::Dependency
15
+ name: json
16
+ requirement: !ruby/object:Gem::Requirement
17
+ requirements:
18
+ - - ">="
19
+ - !ruby/object:Gem::Version
20
+ version: 2.3.0
21
+ type: :runtime
22
+ prerelease: false
23
+ version_requirements: !ruby/object:Gem::Requirement
24
+ requirements:
25
+ - - ">="
26
+ - !ruby/object:Gem::Version
27
+ version: 2.3.0
28
+ - !ruby/object:Gem::Dependency
29
+ name: omniauth-oauth2
30
+ requirement: !ruby/object:Gem::Requirement
31
+ requirements:
32
+ - - "~>"
33
+ - !ruby/object:Gem::Version
34
+ version: '1.3'
35
+ type: :runtime
36
+ prerelease: false
37
+ version_requirements: !ruby/object:Gem::Requirement
38
+ requirements:
39
+ - - "~>"
40
+ - !ruby/object:Gem::Version
41
+ version: '1.3'
42
+ - !ruby/object:Gem::Dependency
43
+ name: bundler
44
+ requirement: !ruby/object:Gem::Requirement
45
+ requirements:
46
+ - - "~>"
47
+ - !ruby/object:Gem::Version
48
+ version: '2.0'
49
+ type: :development
50
+ prerelease: false
51
+ version_requirements: !ruby/object:Gem::Requirement
52
+ requirements:
53
+ - - "~>"
54
+ - !ruby/object:Gem::Version
55
+ version: '2.0'
56
+ description: OmniAuth strategy for Line
57
+ email:
58
+ - marsz330@gmail.com
59
+ executables: []
60
+ extensions: []
61
+ extra_rdoc_files: []
62
+ files:
63
+ - ".gitignore"
64
+ - Gemfile
65
+ - Gemfile.lock
66
+ - README.md
67
+ - Rakefile
68
+ - lib/omniauth-line-messenger.rb
69
+ - lib/omniauth-line-messenger/version.rb
70
+ - lib/omniauth/strategies/line_messenger.rb
71
+ - omniauth-line-messenger.gemspec
72
+ - spec/omniauth/strategies/line_messenger_spec.rb
73
+ - spec/spec_helper.rb
74
+ homepage: https://github.com/marsz/omniauth-line-messenger
75
+ licenses:
76
+ - MIT
77
+ metadata: {}
78
+ post_install_message:
79
+ rdoc_options: []
80
+ require_paths:
81
+ - lib
82
+ required_ruby_version: !ruby/object:Gem::Requirement
83
+ requirements:
84
+ - - ">="
85
+ - !ruby/object:Gem::Version
86
+ version: '0'
87
+ required_rubygems_version: !ruby/object:Gem::Requirement
88
+ requirements:
89
+ - - ">="
90
+ - !ruby/object:Gem::Version
91
+ version: '0'
92
+ requirements: []
93
+ rubygems_version: 3.1.6
94
+ signing_key:
95
+ specification_version: 4
96
+ summary: OmniAuth strategy for Line
97
+ test_files:
98
+ - spec/omniauth/strategies/line_messenger_spec.rb
99
+ - spec/spec_helper.rb