-
Notifications
You must be signed in to change notification settings - Fork 36
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #380 from codeforjapan/line_login
Support LINE Login
- Loading branch information
Showing
22 changed files
with
342 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
# frozen_string_literal: true | ||
|
||
def setup_provider_proc(provider, config_mapping = {}) | ||
lambda do |env| | ||
request = Rack::Request.new(env) | ||
organization = Decidim::Organization.find_by(host: request.host) | ||
provider_config = organization.enabled_omniauth_providers[provider] | ||
|
||
config_mapping.each do |option_key, config_key| | ||
env["omniauth.strategy"].options[option_key] = provider_config[config_key] | ||
end | ||
end | ||
end | ||
|
||
Rails.application.config.middleware.use OmniAuth::Builder do | ||
omniauth_config = Rails.application.secrets[:omniauth] | ||
|
||
if omniauth_config && omniauth_config[:line_login].present? | ||
require "omniauth-line_login" | ||
provider( | ||
:line_login, | ||
setup: setup_provider_proc(:line_login, client_id: :client_id, client_secret: :client_secret) | ||
) | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
en: | ||
decidim: | ||
system: | ||
organizations: | ||
omniauth_settings: | ||
line_login: | ||
client_id: Channel ID | ||
client_secret: Channel secret |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
ja: | ||
decidim: | ||
system: | ||
organizations: | ||
omniauth_settings: | ||
line_login: | ||
client_id: チャンネルID | ||
client_secret: チャンネルシークレット |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
/.bundle/ | ||
/.yardoc | ||
/_yardoc/ | ||
/coverage/ | ||
/doc/ | ||
/pkg/ | ||
/spec/reports/ | ||
/tmp/ | ||
|
||
# rspec failure tracking | ||
.rspec_status |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
--format documentation | ||
--color | ||
--require spec_helper |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
AllCops: | ||
NewCops: enable | ||
|
||
Naming/FileName: | ||
Exclude: | ||
- 'lib/omniauth-line_login.rb' |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
# frozen_string_literal: true | ||
|
||
source 'https://rubygems.org' | ||
|
||
# Specify your gem's dependencies in omniauth-line_login.gemspec | ||
gemspec | ||
|
||
gem 'rake', '~> 13.0' | ||
|
||
gem 'rspec', '~> 3.0' |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,60 @@ | ||
PATH | ||
remote: . | ||
specs: | ||
omniauth-line_login (0.1.0) | ||
omniauth-oauth2 | ||
|
||
GEM | ||
remote: https://rubygems.org/ | ||
specs: | ||
diff-lcs (1.5.0) | ||
faraday (2.2.0) | ||
faraday-net_http (~> 2.0) | ||
ruby2_keywords (>= 0.0.4) | ||
faraday-net_http (2.0.2) | ||
hashie (5.0.0) | ||
jwt (2.3.0) | ||
multi_json (1.15.0) | ||
multi_xml (0.6.0) | ||
oauth2 (1.4.9) | ||
faraday (>= 0.17.3, < 3.0) | ||
jwt (>= 1.0, < 3.0) | ||
multi_json (~> 1.3) | ||
multi_xml (~> 0.5) | ||
rack (>= 1.2, < 3) | ||
omniauth (2.1.0) | ||
hashie (>= 3.4.6) | ||
rack (>= 2.2.3) | ||
rack-protection | ||
omniauth-oauth2 (1.7.2) | ||
oauth2 (~> 1.4) | ||
omniauth (>= 1.9, < 3) | ||
rack (2.2.3) | ||
rack-protection (2.2.0) | ||
rack | ||
rake (13.0.6) | ||
rspec (3.11.0) | ||
rspec-core (~> 3.11.0) | ||
rspec-expectations (~> 3.11.0) | ||
rspec-mocks (~> 3.11.0) | ||
rspec-core (3.11.0) | ||
rspec-support (~> 3.11.0) | ||
rspec-expectations (3.11.0) | ||
diff-lcs (>= 1.2.0, < 2.0) | ||
rspec-support (~> 3.11.0) | ||
rspec-mocks (3.11.1) | ||
diff-lcs (>= 1.2.0, < 2.0) | ||
rspec-support (~> 3.11.0) | ||
rspec-support (3.11.0) | ||
ruby2_keywords (0.0.5) | ||
|
||
PLATFORMS | ||
arm64-darwin-21 | ||
|
||
DEPENDENCIES | ||
omniauth-line_login! | ||
rake (~> 13.0) | ||
rspec (~> 3.0) | ||
|
||
BUNDLED WITH | ||
2.3.11 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
# OmniAuth::LineLogin | ||
|
||
Welcome to your new gem! In this directory, you'll find the files you need to be able to package up your Ruby library into a gem. Put your Ruby code in the file `lib/omniauth/line_login`. To experiment with that code, run `bin/console` for an interactive prompt. | ||
|
||
TODO: Delete this and the text above, and describe your gem | ||
|
||
## Installation | ||
|
||
Install the gem and add to the application's Gemfile by executing: | ||
|
||
$ bundle add omniauth-line_login | ||
|
||
If bundler is not being used to manage dependencies, install the gem by executing: | ||
|
||
$ gem install omniauth-line_login | ||
|
||
## Usage | ||
|
||
TODO: Write usage instructions here | ||
|
||
## Development | ||
|
||
After checking out the repo, run `bin/setup` to install dependencies. Then, run `rake spec` to run the tests. You can also run `bin/console` for an interactive prompt that will allow you to experiment. | ||
|
||
To install this gem onto your local machine, run `bundle exec rake install`. To release a new version, update the version number in `version.rb`, and then run `bundle exec rake release`, which will create a git tag for the version, push git commits and the created tag, and push the `.gem` file to [rubygems.org](https://rubygems.org). | ||
|
||
## Contributing | ||
|
||
Bug reports and pull requests are welcome on GitHub at https://github.com/takahashim/omniauth-line_login. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
# frozen_string_literal: true | ||
|
||
require 'bundler/gem_tasks' | ||
require 'rspec/core/rake_task' | ||
|
||
RSpec::Core::RakeTask.new(:spec) | ||
|
||
task default: :spec |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
#!/usr/bin/env ruby | ||
# frozen_string_literal: true | ||
|
||
require 'bundler/setup' | ||
require 'omniauth/line_login' | ||
|
||
# You can add fixtures and/or initialization code here to make experimenting | ||
# with your gem easier. You can also use a different console, if you like. | ||
|
||
# (If you use this, don't forget to add pry to your Gemfile!) | ||
# require "pry" | ||
# Pry.start | ||
|
||
require 'irb' | ||
IRB.start(__FILE__) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
#!/usr/bin/env bash | ||
set -euo pipefail | ||
IFS=$'\n\t' | ||
set -vx | ||
|
||
bundle install | ||
|
||
# Do any other automated setup that you need to do here |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
# frozen_string_literal: true | ||
|
||
require_relative 'omniauth/line_login/version' | ||
require_relative 'omniauth/line_login/error' | ||
require_relative 'omniauth/strategies/line_login' |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
# frozen_string_literal: true | ||
|
||
module OmniAuth | ||
module LineLogin | ||
class Error < StandardError; end | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
# frozen_string_literal: true | ||
|
||
module OmniAuth | ||
module LineLogin | ||
VERSION = '0.1.0' | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,58 @@ | ||
# frozen_string_literal: true | ||
|
||
module OmniAuth | ||
module Strategies | ||
# OmniAuth Strategy for LINE Login | ||
class LineLogin < OmniAuth::Strategies::OAuth2 | ||
option :name, 'line_login' | ||
option :scope, 'profile openid' | ||
|
||
option :client_options, { | ||
site: 'https://api.line.me', | ||
authorize_url: 'https://access.line.me/oauth2/v2.1/authorize', | ||
token_url: '/oauth2/v2.1/token' | ||
} | ||
|
||
uid { raw_info['sub'] } | ||
|
||
info do | ||
{ | ||
user_id: raw_info['sub'], | ||
name: raw_info['name'], | ||
email: raw_info['email'], | ||
image: raw_info['picture'] | ||
} | ||
end | ||
|
||
def raw_info | ||
@raw_info ||= verify_id_token | ||
end | ||
|
||
private | ||
|
||
def authorize_params | ||
super.tap do |params| | ||
params[:nonce] = SecureRandom.uuid | ||
session['omniauth.nonce'] = params[:nonce] | ||
end | ||
end | ||
|
||
def callback_url | ||
full_host + script_name + callback_path | ||
end | ||
|
||
def verify_id_token | ||
@id_token_payload ||= client.request(:post, 'https://api.line.me/oauth2/v2.1/verify', | ||
{ | ||
body: { | ||
id_token: access_token['id_token'], | ||
client_id: options.client_id, | ||
nonce: session.delete('omniauth.nonce') | ||
} | ||
}).parsed | ||
Rails.logger.info("token:#{@id_token_payload.inspect}") | ||
@id_token_payload | ||
end | ||
end | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
# frozen_string_literal: true | ||
|
||
require_relative 'lib/omniauth/line_login/version' | ||
|
||
Gem::Specification.new do |spec| | ||
spec.name = 'omniauth-line_login' | ||
spec.version = OmniAuth::LineLogin::VERSION | ||
spec.authors = ['takahashim'] | ||
spec.email = ['takahashimm@gmail.com'] | ||
|
||
spec.summary = 'Unofficial OmniAuth Strategy for LINE Login' | ||
spec.description = 'Unofficial OmniAuth Strategy for LINE Login' | ||
spec.homepage = 'https://github.com/takahashim/omniauth-line_login' | ||
spec.required_ruby_version = '>= 2.6.0' # rubocop:disable Gemspec/RequiredRubyVersion | ||
|
||
spec.metadata['homepage_uri'] = spec.homepage | ||
# spec.metadata["source_code_uri"] = "TODO: Put your gem's public repo URL here." | ||
# spec.metadata["changelog_uri"] = "TODO: Put your gem's CHANGELOG.md URL here." | ||
|
||
# Specify which files should be added to the gem when it is released. | ||
# The `git ls-files -z` loads the files in the RubyGem that have been added into git. | ||
spec.files = Dir.chdir(__dir__) do | ||
`git ls-files -z`.split("\x0").reject do |f| | ||
(f == __FILE__) || f.match(%r{\A(?:(?:bin|test|spec|features)/|\.(?:git|travis|circleci)|appveyor)}) | ||
end | ||
end | ||
spec.bindir = 'exe' | ||
spec.executables = spec.files.grep(%r{\Aexe/}) { |f| File.basename(f) } | ||
spec.require_paths = ['lib'] | ||
|
||
spec.add_dependency 'omniauth-oauth2' | ||
|
||
# For more information and examples about making a new gem, check out our | ||
# guide at: https://bundler.io/guides/creating_gem.html | ||
spec.metadata['rubygems_mfa_required'] = 'true' | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
module OmniAuth | ||
module LineLogin | ||
VERSION: String | ||
# See the writing guide of rbs: https://github.com/ruby/rbs#guides | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
# frozen_string_literal: true | ||
|
||
require 'omniauth/line_login' | ||
|
||
RSpec.configure do |config| | ||
# Enable flags like --only-failures and --next-failure | ||
config.example_status_persistence_file_path = '.rspec_status' | ||
|
||
# Disable RSpec exposing methods globally on `Module` and `main` | ||
config.disable_monkey_patching! | ||
|
||
config.expect_with :rspec do |c| | ||
c.syntax = :expect | ||
end | ||
end |