diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..e43c4a7 --- /dev/null +++ b/.gitignore @@ -0,0 +1,4 @@ +/coverage +/coverage/* +*.DS_Store +*.gem diff --git a/Gemfile.lock b/Gemfile.lock new file mode 100644 index 0000000..3809383 --- /dev/null +++ b/Gemfile.lock @@ -0,0 +1,95 @@ +PATH + remote: . + specs: + omniauth-line-messenger (0.3.1) + json (>= 2.3.0) + omniauth-oauth2 (~> 1.3) + +GEM + remote: https://rubygems.org/ + specs: + addressable (2.8.7) + public_suffix (>= 2.0.2, < 7.0) + base64 (0.2.0) + bigdecimal (3.1.8) + crack (1.0.0) + bigdecimal + rexml + diff-lcs (1.5.1) + docile (1.4.1) + faraday (2.8.1) + base64 + faraday-net_http (>= 2.0, < 3.1) + ruby2_keywords (>= 0.0.4) + faraday-net_http (3.0.2) + hashdiff (1.1.1) + hashie (5.0.0) + json (2.7.2) + jwt (2.9.0) + base64 + multi_xml (0.6.0) + oauth2 (2.0.9) + faraday (>= 0.17.3, < 3.0) + jwt (>= 1.0, < 3.0) + multi_xml (~> 0.5) + rack (>= 1.2, < 4) + snaky_hash (~> 2.0) + version_gem (~> 1.1) + omniauth (2.1.2) + hashie (>= 3.4.6) + rack (>= 2.2.3) + rack-protection + omniauth-oauth2 (1.8.0) + oauth2 (>= 1.4, < 3) + omniauth (~> 2.0) + public_suffix (5.1.1) + rack (3.1.7) + rack-protection (3.0.6) + rack + rack-test (2.1.0) + rack (>= 1.3) + rake (13.2.1) + rexml (3.3.7) + rspec (3.13.0) + rspec-core (~> 3.13.0) + rspec-expectations (~> 3.13.0) + rspec-mocks (~> 3.13.0) + rspec-core (3.13.1) + rspec-support (~> 3.13.0) + rspec-expectations (3.13.3) + diff-lcs (>= 1.2.0, < 2.0) + rspec-support (~> 3.13.0) + rspec-mocks (3.13.1) + diff-lcs (>= 1.2.0, < 2.0) + rspec-support (~> 3.13.0) + rspec-support (3.13.1) + ruby2_keywords (0.0.5) + simplecov (0.22.0) + docile (~> 1.1) + simplecov-html (~> 0.11) + simplecov_json_formatter (~> 0.1) + simplecov-html (0.13.1) + simplecov_json_formatter (0.1.4) + snaky_hash (2.0.1) + hashie + version_gem (~> 1.1, >= 1.1.1) + version_gem (1.1.4) + webmock (3.23.1) + addressable (>= 2.8.0) + crack (>= 0.3.2) + hashdiff (>= 0.4.0, < 2.0.0) + +PLATFORMS + arm64-darwin-22 + +DEPENDENCIES + bundler (~> 2.0) + omniauth-line-messenger! + rack-test + rake + rspec (~> 3.2) + simplecov + webmock + +BUNDLED WITH + 2.4.22 diff --git a/README.md b/README.md index c6370f5..6aa22b3 100644 --- a/README.md +++ b/README.md @@ -9,7 +9,7 @@ Supports the OpenID Connect Web Login. Read the Line developers docs for more de First start by adding this gem to your Gemfile: ```ruby -gem 'omniauth-line' +gem 'omniauth-line-messenger' ``` Next, tell OmniAuth about this provider. For a Rails app, your `config/initializers/omniauth.rb` file should look like this: @@ -32,6 +32,7 @@ An example auth hash available in `request.env['omniauth.auth']`: :name => "yamada tarou", :image => "http://dl.profile.line.naver.jp/xxxxx", :description => "breakfast now.", + :email => "foo@bar.com" }, :credentials => { :token => "a1b2c3d4...", # The OAuth 2.0 access token diff --git a/lib/omniauth-line.rb b/lib/omniauth-line-messenger.rb similarity index 100% rename from lib/omniauth-line.rb rename to lib/omniauth-line-messenger.rb diff --git a/lib/omniauth-line/version.rb b/lib/omniauth-line/version.rb index 9ff47e0..55ce2e4 100644 --- a/lib/omniauth-line/version.rb +++ b/lib/omniauth-line/version.rb @@ -1,5 +1,5 @@ module OmniAuth module Line - VERSION = "0.1.0" + VERSION = "0.3.2" end end diff --git a/lib/omniauth/strategies/line.rb b/lib/omniauth/strategies/line.rb index e3fcbcc..0335589 100644 --- a/lib/omniauth/strategies/line.rb +++ b/lib/omniauth/strategies/line.rb @@ -5,7 +5,7 @@ module OmniAuth module Strategies class Line < OmniAuth::Strategies::OAuth2 option :name, 'line' - option :scope, 'profile openid' + option :scope, 'profile openid email' option :client_options, { site: 'https://access.line.me', @@ -23,14 +23,16 @@ def callback_url # Fixes regression in omniauth-oauth2 v1.4.0 by https://github.com/intridea/omniauth-oauth2/commit/85fdbe117c2a4400d001a6368cc359d88f40abc7 options[:callback_url] || (full_host + script_name + callback_path) end - + uid { raw_info['userId'] } info do { name: raw_info['displayName'], image: raw_info['pictureUrl'], - description: raw_info['statusMessage'] + description: raw_info['statusMessage'], + email: fetch_email + # email: JWT.decode(access_token.params['id_token'], options['client_secret']).first&.dig('email') } end @@ -41,6 +43,12 @@ def raw_info raise ::Timeout::Error end + def fetch_email + data = JSON.load(access_token.post('oauth2/v2.1/verify', params: { id_token: access_token.params['id_token'], client_id: options['client_id'] }).body) + data['email'] + rescue ::Errno::ETIMEDOUT + raise ::Timeout::Error + end end end end diff --git a/omniauth-line.gemspec b/omniauth-line-messenger.gemspec similarity index 77% rename from omniauth-line.gemspec rename to omniauth-line-messenger.gemspec index 8b5d63c..fa2d1ce 100644 --- a/omniauth-line.gemspec +++ b/omniauth-line-messenger.gemspec @@ -3,11 +3,11 @@ $:.push File.expand_path("../lib", __FILE__) require "omniauth-line/version" Gem::Specification.new do |s| - s.name = "omniauth-line" + s.name = "omniauth-line-messenger" s.version = OmniAuth::Line::VERSION - s.authors = ["kazasiki"] - s.email = ["kazasiki@gmail.com"] - s.homepage = "https://github.com/kazasiki/omniauth-line" + s.authors = ["kazasiki", "marsz"] + s.email = ["marsz330@gmail.com"] + s.homepage = "https://github.com/marsz/omniauth-line-messenger" s.description = %q{OmniAuth strategy for Line} s.summary = s.description s.license = "MIT" diff --git a/spec/omniauth/strategies/line_spec.rb b/spec/omniauth/strategies/line_spec.rb index ee787d2..d755a40 100644 --- a/spec/omniauth/strategies/line_spec.rb +++ b/spec/omniauth/strategies/line_spec.rb @@ -33,6 +33,7 @@ describe 'uid' do before do allow(subject).to receive(:raw_info).and_return(raw_info_hash) + allow(subject).to receive(:fetch_email).and_return('foo@bar.com') end it 'should returns the uid' do @@ -43,6 +44,7 @@ describe 'info' do before do allow(subject).to receive(:raw_info).and_return(raw_info_hash) + allow(subject).to receive(:fetch_email).and_return('foo@bar.com') end it 'should returns the name' do diff --git a/spec/spec_helper.rb b/spec/spec_helper.rb index bf2ffa6..44b74e9 100644 --- a/spec/spec_helper.rb +++ b/spec/spec_helper.rb @@ -8,7 +8,7 @@ require 'rack/test' require 'webmock/rspec' require 'omniauth' -require 'omniauth-line' +require 'omniauth-line-messenger' RSpec.configure do |config| config.include WebMock::API