omniauth-line-v2 2.0.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 +7 -0
- data/.rspec +3 -0
- data/CHANGELOG.md +25 -0
- data/LICENSE.txt +21 -0
- data/README.md +144 -0
- data/Rakefile +11 -0
- data/lib/omniauth/line_v2/version.rb +7 -0
- data/lib/omniauth/strategies/line.rb +112 -0
- data/lib/omniauth-line-v2.rb +4 -0
- metadata +83 -0
checksums.yaml
ADDED
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
---
|
|
2
|
+
SHA256:
|
|
3
|
+
metadata.gz: 23d3d840f82f210a27ca394fe1c0823bc3f965e6a32b465b3ee3454a83050346
|
|
4
|
+
data.tar.gz: ed2c6fe30e0002128394dd5ca25b651b43a4637fce7a6e53908770e30361bd60
|
|
5
|
+
SHA512:
|
|
6
|
+
metadata.gz: 887df29c981e129db138948ed7fda87ace372554c8590352af613eeb713b0af99f7a9a06fb979e5fcde447f3d785af32c1f71bd8516999eccf44d53ac3d4e644
|
|
7
|
+
data.tar.gz: 4c583332f9294651a9e1b3053148d5dd825bee51edabeeaa0a7d1c90286b82884744f94bb3ce6fd00a2b75d37291fabc469f37bdba624dbb13542e8eaee29c62
|
data/.rspec
ADDED
data/CHANGELOG.md
ADDED
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
# Changelog
|
|
2
|
+
|
|
3
|
+
## [2.0.0] - 2025-11-28
|
|
4
|
+
|
|
5
|
+
- Rename strategy from `LineV21` to `Line`
|
|
6
|
+
|
|
7
|
+
## [1.2.0] - 2025-11-03
|
|
8
|
+
|
|
9
|
+
- Refactor: Remove redundant user info endpoint call
|
|
10
|
+
- Test: Update test
|
|
11
|
+
- Other: Update README.md
|
|
12
|
+
|
|
13
|
+
## [1.1.0] - 2025-08-02
|
|
14
|
+
|
|
15
|
+
- Refactor: Refactor `OmniAuth::Strategies::LineV21#authorize_params`
|
|
16
|
+
- Test: Update test
|
|
17
|
+
|
|
18
|
+
## [1.0.0] - 2025-08-01
|
|
19
|
+
|
|
20
|
+
- New: Generate nonce parameter automatically for security
|
|
21
|
+
- New: Call fail! when ID token verification response contains error
|
|
22
|
+
|
|
23
|
+
## [0.0.0] - 2025-07-26
|
|
24
|
+
|
|
25
|
+
- Initial release
|
data/LICENSE.txt
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
The MIT License (MIT)
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2025 Masahiro
|
|
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
|
|
13
|
+
all 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
|
|
21
|
+
THE SOFTWARE.
|
data/README.md
ADDED
|
@@ -0,0 +1,144 @@
|
|
|
1
|
+
# OmniauthLineV2
|
|
2
|
+
|
|
3
|
+
[](https://github.com/cadenza-tech/omniauth-line-v2/blob/main/LICENSE.txt) [](https://github.com/cadenza-tech/omniauth-line-v2/blob/main/CHANGELOG.md) [](https://github.com/cadenza-tech/omniauth-line-v2/actions?query=workflow%3Arelease) [](https://github.com/cadenza-tech/omniauth-line-v2/actions?query=workflow%3Atest) [](https://github.com/cadenza-tech/omniauth-line-v2/actions?query=workflow%3Alint)
|
|
4
|
+
|
|
5
|
+
LINE strategy for OmniAuth.
|
|
6
|
+
|
|
7
|
+
- [Installation](#installation)
|
|
8
|
+
- [Usage](#usage)
|
|
9
|
+
- [Rails Configuration with Devise](#rails-configuration-with-devise)
|
|
10
|
+
- [Configuration Options](#configuration-options)
|
|
11
|
+
- [Auth Hash](#auth-hash)
|
|
12
|
+
- [Changelog](#changelog)
|
|
13
|
+
- [Contributing](#contributing)
|
|
14
|
+
- [License](#license)
|
|
15
|
+
- [Code of Conduct](#code-of-conduct)
|
|
16
|
+
- [Sponsor](#sponsor)
|
|
17
|
+
|
|
18
|
+
## Installation
|
|
19
|
+
|
|
20
|
+
Install the gem and add to the application's Gemfile by executing:
|
|
21
|
+
|
|
22
|
+
```bash
|
|
23
|
+
bundle add omniauth-line-v2
|
|
24
|
+
```
|
|
25
|
+
|
|
26
|
+
If bundler is not being used to manage dependencies, install the gem by executing:
|
|
27
|
+
|
|
28
|
+
```bash
|
|
29
|
+
gem install omniauth-line-v2
|
|
30
|
+
```
|
|
31
|
+
|
|
32
|
+
## Usage
|
|
33
|
+
|
|
34
|
+
### Rails Configuration with Devise
|
|
35
|
+
|
|
36
|
+
Add the following to `config/initializers/devise.rb`:
|
|
37
|
+
|
|
38
|
+
```ruby
|
|
39
|
+
# config/initializers/devise.rb
|
|
40
|
+
Devise.setup do |config|
|
|
41
|
+
config.omniauth :line, ENV['LINE_CHANNEL_ID'], ENV['LINE_CHANNEL_SECRET']
|
|
42
|
+
end
|
|
43
|
+
```
|
|
44
|
+
|
|
45
|
+
Add the OmniAuth callbacks routes to `config/routes.rb`:
|
|
46
|
+
|
|
47
|
+
```ruby
|
|
48
|
+
# config/routes.rb
|
|
49
|
+
Rails.application.routes.draw do
|
|
50
|
+
devise_for :users, controllers: { omniauth_callbacks: 'users/omniauth_callbacks' }
|
|
51
|
+
end
|
|
52
|
+
```
|
|
53
|
+
|
|
54
|
+
Add the OmniAuth configuration to your Devise model:
|
|
55
|
+
|
|
56
|
+
```ruby
|
|
57
|
+
class User < ApplicationRecord
|
|
58
|
+
devise :database_authenticatable, :registerable,
|
|
59
|
+
:recoverable, :rememberable, :validatable,
|
|
60
|
+
:omniauthable, omniauth_providers: [:line]
|
|
61
|
+
end
|
|
62
|
+
```
|
|
63
|
+
|
|
64
|
+
### Configuration Options
|
|
65
|
+
|
|
66
|
+
You can configure several options:
|
|
67
|
+
|
|
68
|
+
```ruby
|
|
69
|
+
# config/initializers/devise.rb
|
|
70
|
+
Devise.setup do |config|
|
|
71
|
+
config.omniauth :line, ENV['LINE_CHANNEL_ID'], ENV['LINE_CHANNEL_SECRET'],
|
|
72
|
+
{
|
|
73
|
+
scope: 'profile openid', # Specify OAuth scopes
|
|
74
|
+
callback_path: '/custom/line/callback', # Custom callback path
|
|
75
|
+
prompt: 'consent', # Optional: force consent screen
|
|
76
|
+
bot_prompt: 'aggressive' # Optional: LINE official account linking
|
|
77
|
+
}
|
|
78
|
+
end
|
|
79
|
+
```
|
|
80
|
+
|
|
81
|
+
Available scopes:
|
|
82
|
+
|
|
83
|
+
- `profile` - Access to user's display name and profile image
|
|
84
|
+
- `openid` - Required for ID token (includes user identifier)
|
|
85
|
+
- `email` - Access to user's email address
|
|
86
|
+
|
|
87
|
+
### Auth Hash
|
|
88
|
+
|
|
89
|
+
After successful authentication, the auth hash will be available in `request.env['omniauth.auth']`:
|
|
90
|
+
|
|
91
|
+
```ruby
|
|
92
|
+
{
|
|
93
|
+
provider: 'line',
|
|
94
|
+
uid: 'U4af4980629...',
|
|
95
|
+
info: {
|
|
96
|
+
name: 'Taro Line',
|
|
97
|
+
nickname: 'U4af4980629...',
|
|
98
|
+
image: 'https://profile.line-scdn.net/...',
|
|
99
|
+
email: 'taro.line@example.com'
|
|
100
|
+
},
|
|
101
|
+
credentials: {
|
|
102
|
+
token: 'bNl4YEFPI/hjFWhTqexp4MuEw5YPs...',
|
|
103
|
+
expires: true,
|
|
104
|
+
expires_at: 1504169092,
|
|
105
|
+
refresh_token: 'Aa1FdeggRhTnPNNpxr8p'
|
|
106
|
+
},
|
|
107
|
+
extra: {
|
|
108
|
+
id_token: 'eyJhbGciOiJIUzI1NiJ9...',
|
|
109
|
+
id_info: {
|
|
110
|
+
iss: 'https://access.line.me',
|
|
111
|
+
sub: 'U4af4980629...',
|
|
112
|
+
aud: '1234567890',
|
|
113
|
+
exp: 1504169092,
|
|
114
|
+
iat: 1504263657,
|
|
115
|
+
auth_time: 1504263657,
|
|
116
|
+
nonce: '0987654asdf',
|
|
117
|
+
amr: ['pwd'],
|
|
118
|
+
name: 'Taro Line',
|
|
119
|
+
picture: 'https://profile.line-scdn.net/...',
|
|
120
|
+
email: 'taro.line@example.com'
|
|
121
|
+
}
|
|
122
|
+
}
|
|
123
|
+
}
|
|
124
|
+
```
|
|
125
|
+
|
|
126
|
+
## Changelog
|
|
127
|
+
|
|
128
|
+
See [CHANGELOG.md](https://github.com/cadenza-tech/omniauth-line-v2/blob/main/CHANGELOG.md).
|
|
129
|
+
|
|
130
|
+
## Contributing
|
|
131
|
+
|
|
132
|
+
Bug reports and pull requests are welcome on GitHub at https://github.com/cadenza-tech/omniauth-line-v2. This project is intended to be a safe, welcoming space for collaboration, and contributors are expected to adhere to the [code of conduct](https://github.com/cadenza-tech/omniauth-line-v2/blob/main/CODE_OF_CONDUCT.md).
|
|
133
|
+
|
|
134
|
+
## License
|
|
135
|
+
|
|
136
|
+
The gem is available as open source under the terms of the [MIT License](https://github.com/cadenza-tech/omniauth-line-v2/blob/main/LICENSE.txt).
|
|
137
|
+
|
|
138
|
+
## Code of Conduct
|
|
139
|
+
|
|
140
|
+
Everyone interacting in the OmniauthLineV2 project's codebases, issue trackers, chat rooms and mailing lists is expected to follow the [code of conduct](https://github.com/cadenza-tech/omniauth-line-v2/blob/main/CODE_OF_CONDUCT.md).
|
|
141
|
+
|
|
142
|
+
## Sponsor
|
|
143
|
+
|
|
144
|
+
You can sponsor this project on [Patreon](https://patreon.com/CadenzaTech).
|
data/Rakefile
ADDED
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
require 'bundler/gem_tasks'
|
|
4
|
+
require 'rspec/core/rake_task'
|
|
5
|
+
require 'rubocop/rake_task'
|
|
6
|
+
|
|
7
|
+
RSpec::Core::RakeTask.new(:spec)
|
|
8
|
+
|
|
9
|
+
RuboCop::RakeTask.new(:rubocop) do |task|
|
|
10
|
+
task.options = ['--format', ENV['RUBOCOP_FORMAT']] if ENV['RUBOCOP_FORMAT']
|
|
11
|
+
end
|
|
@@ -0,0 +1,112 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
require 'omniauth-oauth2'
|
|
4
|
+
require 'uri'
|
|
5
|
+
|
|
6
|
+
module OmniAuth
|
|
7
|
+
module Strategies
|
|
8
|
+
class Line < OmniAuth::Strategies::OAuth2
|
|
9
|
+
DEFAULT_SCOPE = 'profile openid email'
|
|
10
|
+
ID_TOKEN_VERIFY_URL = 'https://api.line.me/oauth2/v2.1/verify'
|
|
11
|
+
|
|
12
|
+
option :name, 'line'
|
|
13
|
+
option :client_options, {
|
|
14
|
+
site: 'https://access.line.me',
|
|
15
|
+
authorize_url: '/oauth2/v2.1/authorize',
|
|
16
|
+
token_url: 'https://api.line.me/oauth2/v2.1/token'
|
|
17
|
+
}
|
|
18
|
+
option :authorize_options, [:scope, :state, :nonce, :prompt, :bot_prompt]
|
|
19
|
+
option :scope, DEFAULT_SCOPE
|
|
20
|
+
|
|
21
|
+
uid { id_token_info[:decoded]['sub'] }
|
|
22
|
+
|
|
23
|
+
info do
|
|
24
|
+
prune!({
|
|
25
|
+
name: id_token_info[:decoded]['name'],
|
|
26
|
+
nickname: id_token_info[:decoded]['sub'],
|
|
27
|
+
image: id_token_info[:decoded]['picture'],
|
|
28
|
+
email: id_token_info[:decoded]['email']
|
|
29
|
+
})
|
|
30
|
+
end
|
|
31
|
+
|
|
32
|
+
extra do
|
|
33
|
+
hash = {}
|
|
34
|
+
hash[:id_token] = id_token_info[:raw] if id_token_info[:raw]
|
|
35
|
+
hash[:id_info] = id_token_info[:decoded] if id_token_info[:decoded]
|
|
36
|
+
prune!(hash)
|
|
37
|
+
end
|
|
38
|
+
|
|
39
|
+
credentials do
|
|
40
|
+
hash = { token: access_token.token }
|
|
41
|
+
hash[:expires] = access_token.expires?
|
|
42
|
+
hash[:expires_at] = access_token.expires_at if access_token.expires?
|
|
43
|
+
hash[:refresh_token] = access_token.refresh_token if access_token.refresh_token
|
|
44
|
+
hash
|
|
45
|
+
end
|
|
46
|
+
|
|
47
|
+
def callback_url
|
|
48
|
+
options[:redirect_uri] || (full_host + callback_path)
|
|
49
|
+
end
|
|
50
|
+
|
|
51
|
+
def authorize_params # rubocop:disable Metrics/AbcSize
|
|
52
|
+
super.tap do |params|
|
|
53
|
+
options[:authorize_options].each do |key|
|
|
54
|
+
params[key] = request.params[key.to_s] unless empty?(request.params[key.to_s])
|
|
55
|
+
end
|
|
56
|
+
params[:scope] ||= DEFAULT_SCOPE
|
|
57
|
+
params[:nonce] ||= SecureRandom.hex(24)
|
|
58
|
+
params[:response_type] = 'code'
|
|
59
|
+
session['omniauth.state'] = params[:state] unless empty?(params[:state])
|
|
60
|
+
session['omniauth.nonce'] = params[:nonce] unless empty?(params[:nonce])
|
|
61
|
+
end
|
|
62
|
+
end
|
|
63
|
+
|
|
64
|
+
private
|
|
65
|
+
|
|
66
|
+
def prune!(hash)
|
|
67
|
+
hash.delete_if do |_, value|
|
|
68
|
+
prune!(value) if value.is_a?(Hash)
|
|
69
|
+
empty?(value)
|
|
70
|
+
end
|
|
71
|
+
end
|
|
72
|
+
|
|
73
|
+
def empty?(value)
|
|
74
|
+
value.nil? || (value.respond_to?(:empty?) && value.empty?)
|
|
75
|
+
end
|
|
76
|
+
|
|
77
|
+
def id_token_info
|
|
78
|
+
return @id_token_info if defined?(@id_token_info)
|
|
79
|
+
|
|
80
|
+
@id_token_info = { raw: nil, decoded: nil }
|
|
81
|
+
return @id_token_info unless access_token.params['id_token']
|
|
82
|
+
|
|
83
|
+
@id_token_info[:raw] = access_token.params['id_token']
|
|
84
|
+
@id_token_info[:decoded] = verify_and_decode_id_token(access_token.params['id_token'])
|
|
85
|
+
@id_token_info
|
|
86
|
+
end
|
|
87
|
+
|
|
88
|
+
def verify_and_decode_id_token(id_token)
|
|
89
|
+
params = {
|
|
90
|
+
id_token: id_token,
|
|
91
|
+
client_id: options.client_id
|
|
92
|
+
}
|
|
93
|
+
params[:nonce] = session.delete('omniauth.nonce') if session['omniauth.nonce']
|
|
94
|
+
|
|
95
|
+
response = client.request(
|
|
96
|
+
:post,
|
|
97
|
+
ID_TOKEN_VERIFY_URL,
|
|
98
|
+
headers: {
|
|
99
|
+
'Content-Type' => 'application/x-www-form-urlencoded'
|
|
100
|
+
},
|
|
101
|
+
body: URI.encode_www_form(params)
|
|
102
|
+
).parsed
|
|
103
|
+
|
|
104
|
+
fail!(:id_token_verification_failed, CallbackError.new(:id_token_verification_failed, response['error_description'])) if response['error']
|
|
105
|
+
|
|
106
|
+
response
|
|
107
|
+
rescue StandardError => e
|
|
108
|
+
fail!(:id_token_verification_failed, e)
|
|
109
|
+
end
|
|
110
|
+
end
|
|
111
|
+
end
|
|
112
|
+
end
|
metadata
ADDED
|
@@ -0,0 +1,83 @@
|
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
|
2
|
+
name: omniauth-line-v2
|
|
3
|
+
version: !ruby/object:Gem::Version
|
|
4
|
+
version: 2.0.0
|
|
5
|
+
platform: ruby
|
|
6
|
+
authors:
|
|
7
|
+
- Masahiro
|
|
8
|
+
bindir: exe
|
|
9
|
+
cert_chain: []
|
|
10
|
+
date: 1980-01-02 00:00:00.000000000 Z
|
|
11
|
+
dependencies:
|
|
12
|
+
- !ruby/object:Gem::Dependency
|
|
13
|
+
name: omniauth
|
|
14
|
+
requirement: !ruby/object:Gem::Requirement
|
|
15
|
+
requirements:
|
|
16
|
+
- - "~>"
|
|
17
|
+
- !ruby/object:Gem::Version
|
|
18
|
+
version: '2.0'
|
|
19
|
+
type: :runtime
|
|
20
|
+
prerelease: false
|
|
21
|
+
version_requirements: !ruby/object:Gem::Requirement
|
|
22
|
+
requirements:
|
|
23
|
+
- - "~>"
|
|
24
|
+
- !ruby/object:Gem::Version
|
|
25
|
+
version: '2.0'
|
|
26
|
+
- !ruby/object:Gem::Dependency
|
|
27
|
+
name: omniauth-oauth2
|
|
28
|
+
requirement: !ruby/object:Gem::Requirement
|
|
29
|
+
requirements:
|
|
30
|
+
- - "~>"
|
|
31
|
+
- !ruby/object:Gem::Version
|
|
32
|
+
version: '1.8'
|
|
33
|
+
type: :runtime
|
|
34
|
+
prerelease: false
|
|
35
|
+
version_requirements: !ruby/object:Gem::Requirement
|
|
36
|
+
requirements:
|
|
37
|
+
- - "~>"
|
|
38
|
+
- !ruby/object:Gem::Version
|
|
39
|
+
version: '1.8'
|
|
40
|
+
description: LINE strategy for OmniAuth
|
|
41
|
+
email:
|
|
42
|
+
- watanabe@cadenza-tech.com
|
|
43
|
+
executables: []
|
|
44
|
+
extensions: []
|
|
45
|
+
extra_rdoc_files: []
|
|
46
|
+
files:
|
|
47
|
+
- ".rspec"
|
|
48
|
+
- CHANGELOG.md
|
|
49
|
+
- LICENSE.txt
|
|
50
|
+
- README.md
|
|
51
|
+
- Rakefile
|
|
52
|
+
- lib/omniauth-line-v2.rb
|
|
53
|
+
- lib/omniauth/line_v2/version.rb
|
|
54
|
+
- lib/omniauth/strategies/line.rb
|
|
55
|
+
homepage: https://github.com/cadenza-tech/omniauth-line-v2/tree/v2.0.0
|
|
56
|
+
licenses:
|
|
57
|
+
- MIT
|
|
58
|
+
metadata:
|
|
59
|
+
homepage_uri: https://github.com/cadenza-tech/omniauth-line-v2/tree/v2.0.0
|
|
60
|
+
source_code_uri: https://github.com/cadenza-tech/omniauth-line-v2/tree/v2.0.0
|
|
61
|
+
changelog_uri: https://github.com/cadenza-tech/omniauth-line-v2/blob/v2.0.0/CHANGELOG.md
|
|
62
|
+
bug_tracker_uri: https://github.com/cadenza-tech/omniauth-line-v2/issues
|
|
63
|
+
documentation_uri: https://rubydoc.info/gems/omniauth-line-v2/2.0.0
|
|
64
|
+
funding_uri: https://patreon.com/CadenzaTech
|
|
65
|
+
rubygems_mfa_required: 'true'
|
|
66
|
+
rdoc_options: []
|
|
67
|
+
require_paths:
|
|
68
|
+
- lib
|
|
69
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
|
70
|
+
requirements:
|
|
71
|
+
- - ">="
|
|
72
|
+
- !ruby/object:Gem::Version
|
|
73
|
+
version: 2.5.0
|
|
74
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
|
75
|
+
requirements:
|
|
76
|
+
- - ">="
|
|
77
|
+
- !ruby/object:Gem::Version
|
|
78
|
+
version: '0'
|
|
79
|
+
requirements: []
|
|
80
|
+
rubygems_version: 3.6.9
|
|
81
|
+
specification_version: 4
|
|
82
|
+
summary: LINE strategy for OmniAuth
|
|
83
|
+
test_files: []
|