omniauth-line-v2_1 0.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 ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA256:
3
+ metadata.gz: cb969635fc2b09065bebf5373d123f43986a6730036a34329a2d53e6a64cae6e
4
+ data.tar.gz: b78c3a7a5d50a89d6ed15c533467d40c3588be0cf4c05799e957a36994b85ac4
5
+ SHA512:
6
+ metadata.gz: beb775ade24ca083c3732d52a9b3428731d929ce6726170d23813f85f264e841059ed9db1a81de6a0fb963224c5015a4c7595b761bba8d5f427a150f6ace83df
7
+ data.tar.gz: e6d6e1548574c50864d9b49fc445222dda932c94933c9aa96f15803c7d067ce7e1ba7075daf12578c7bc84efb8b2cb5f150590ff730f31987317130d59727567
data/.rspec ADDED
@@ -0,0 +1,3 @@
1
+ --require spec_helper
2
+ --color
3
+ --format documentation
data/CHANGELOG.md ADDED
@@ -0,0 +1,5 @@
1
+ # Changelog
2
+
3
+ ## [0.0.0] - 2025-07-26
4
+
5
+ - 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,150 @@
1
+ # OmniauthLineV2.1
2
+
3
+ [![License](https://img.shields.io/github/license/cadenza-tech/omniauth-line-v2_1?label=License&labelColor=343B42&color=blue)](https://github.com/cadenza-tech/omniauth-line-v2_1/blob/main/LICENSE.txt) [![Tag](https://img.shields.io/github/tag/cadenza-tech/omniauth-line-v2_1?label=Tag&logo=github&labelColor=343B42&color=2EBC4F)](https://github.com/cadenza-tech/omniauth-line-v2_1/blob/main/CHANGELOG.md) [![Release](https://github.com/cadenza-tech/omniauth-line-v2_1/actions/workflows/release.yml/badge.svg)](https://github.com/cadenza-tech/omniauth-line-v2_1/actions?query=workflow%3Arelease) [![Test](https://github.com/cadenza-tech/omniauth-line-v2_1/actions/workflows/test.yml/badge.svg)](https://github.com/cadenza-tech/omniauth-line-v2_1/actions?query=workflow%3Atest) [![Lint](https://github.com/cadenza-tech/omniauth-line-v2_1/actions/workflows/lint.yml/badge.svg)](https://github.com/cadenza-tech/omniauth-line-v2_1/actions?query=workflow%3Alint)
4
+
5
+ LINE Login v2.1 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_1
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_1
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_v2_1, 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_v2_1]
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_v2_1, ENV['LINE_CHANNEL_ID'], ENV['LINE_CHANNEL_SECRET'],
72
+ {
73
+ scope: 'profile openid', # Specify OAuth scopes
74
+ callback_path: '/custom/line_v2_1/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_v2_1',
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
+ raw_info: {
109
+ sub: 'U4af4980629...',
110
+ name: 'Taro Line',
111
+ picture: 'https://profile.line-scdn.net/...',
112
+ email: 'taro.line@example.com'
113
+ },
114
+ id_token: 'eyJhbGciOiJIUzI1NiJ9...',
115
+ id_info: {
116
+ iss: 'https://access.line.me',
117
+ sub: 'U4af4980629...',
118
+ aud: '1234567890',
119
+ exp: 1504169092,
120
+ iat: 1504263657,
121
+ auth_time: 1504263657,
122
+ nonce: '0987654asdf',
123
+ amr: ['pwd'],
124
+ name: 'Taro Line',
125
+ picture: 'https://profile.line-scdn.net/...',
126
+ email: 'taro.line@example.com'
127
+ }
128
+ }
129
+ }
130
+ ```
131
+
132
+ ## Changelog
133
+
134
+ See [CHANGELOG.md](https://github.com/cadenza-tech/omniauth-line-v2_1/blob/main/CHANGELOG.md).
135
+
136
+ ## Contributing
137
+
138
+ Bug reports and pull requests are welcome on GitHub at https://github.com/cadenza-tech/omniauth-line-v2_1. 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_1/blob/main/CODE_OF_CONDUCT.md).
139
+
140
+ ## License
141
+
142
+ The gem is available as open source under the terms of the [MIT License](https://github.com/cadenza-tech/omniauth-line-v2_1/blob/main/LICENSE.txt).
143
+
144
+ ## Code of Conduct
145
+
146
+ Everyone interacting in the OmniauthLineV2.1 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_1/blob/main/CODE_OF_CONDUCT.md).
147
+
148
+ ## Sponsor
149
+
150
+ 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,7 @@
1
+ # frozen_string_literal: true
2
+
3
+ module OmniAuth
4
+ module LineV21
5
+ VERSION = '0.0.0'
6
+ end
7
+ end
@@ -0,0 +1,112 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'omniauth-oauth2'
4
+
5
+ module OmniAuth
6
+ module Strategies
7
+ class LineV21 < OmniAuth::Strategies::OAuth2
8
+ DEFAULT_SCOPE = 'profile openid email'
9
+ USER_INFO_URL = 'https://api.line.me/oauth2/v2.1/userinfo'
10
+ ID_TOKEN_VERIFY_URL = 'https://api.line.me/oauth2/v2.1/verify'
11
+
12
+ option :name, 'line_v2_1'
13
+
14
+ option :client_options, {
15
+ site: 'https://access.line.me',
16
+ authorize_url: '/oauth2/v2.1/authorize',
17
+ token_url: 'https://api.line.me/oauth2/v2.1/token'
18
+ }
19
+
20
+ option :authorize_options, [:scope, :state, :nonce, :prompt, :bot_prompt]
21
+
22
+ option :scope, DEFAULT_SCOPE
23
+
24
+ uid { raw_info['sub'] }
25
+
26
+ info do
27
+ prune!({
28
+ name: raw_info['name'],
29
+ nickname: raw_info['sub'],
30
+ image: raw_info['picture'],
31
+ email: id_token_info[:decoded]['email']
32
+ })
33
+ end
34
+
35
+ extra do
36
+ hash = {}
37
+ hash[:raw_info] = raw_info unless skip_info?
38
+ hash[:id_token] = id_token_info[:raw] if id_token_info[:raw]
39
+ hash[:id_info] = id_token_info[:decoded] if id_token_info[:decoded]
40
+ prune!(hash)
41
+ end
42
+
43
+ credentials do
44
+ hash = { token: access_token.token }
45
+ hash[:expires] = access_token.expires?
46
+ hash[:expires_at] = access_token.expires_at if access_token.expires?
47
+ hash[:refresh_token] = access_token.refresh_token if access_token.refresh_token
48
+ hash
49
+ end
50
+
51
+ def raw_info
52
+ @raw_info ||= access_token.get(USER_INFO_URL, headers: { 'Authorization' => "Bearer #{access_token.token}" }).parsed
53
+ end
54
+
55
+ def callback_url
56
+ options[:redirect_uri] || (full_host + callback_path)
57
+ end
58
+
59
+ def authorize_params
60
+ super.tap do |params|
61
+ %w[scope state nonce prompt bot_prompt].each do |v|
62
+ params[v.to_sym] = request.params[v] if request.params[v]
63
+ end
64
+ params[:scope] ||= DEFAULT_SCOPE
65
+ params[:response_type] = 'code'
66
+ session['omniauth.state'] = params[:state] if params[:state]
67
+ session['omniauth.nonce'] = params[:nonce] if params[:nonce]
68
+ end
69
+ end
70
+
71
+ private
72
+
73
+ def prune!(hash)
74
+ hash.delete_if do |_, value|
75
+ prune!(value) if value.is_a?(Hash)
76
+ value.nil? || (value.respond_to?(:empty?) && value.empty?)
77
+ end
78
+ end
79
+
80
+ def id_token_info
81
+ return @id_token_info if defined?(@id_token_info)
82
+
83
+ @id_token_info = { raw: nil, decoded: nil }
84
+ return @id_token_info unless access_token.params['id_token']
85
+
86
+ @id_token_info[:raw] = access_token.params['id_token']
87
+ @id_token_info[:decoded] = verify_id_token(access_token.params['id_token'])
88
+ @id_token_info
89
+ end
90
+
91
+ def verify_id_token(id_token)
92
+ params = {
93
+ id_token: id_token,
94
+ client_id: options.client_id
95
+ }
96
+ params[:nonce] = session['omniauth.nonce'] if session['omniauth.nonce']
97
+
98
+ client.request(
99
+ :post,
100
+ ID_TOKEN_VERIFY_URL,
101
+ headers: {
102
+ 'Content-Type' => 'application/x-www-form-urlencoded'
103
+ },
104
+ body: URI.encode_www_form(params)
105
+ ).parsed
106
+ rescue StandardError => e
107
+ log :error, "ID token verification failed: #{e.message}"
108
+ nil
109
+ end
110
+ end
111
+ end
112
+ end
@@ -0,0 +1,4 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'omniauth/line_v2_1/version'
4
+ require 'omniauth/strategies/line_v2_1'
metadata ADDED
@@ -0,0 +1,83 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: omniauth-line-v2_1
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.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 Login v2.1 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_1.rb
53
+ - lib/omniauth/line_v2_1/version.rb
54
+ - lib/omniauth/strategies/line_v2_1.rb
55
+ homepage: https://github.com/cadenza-tech/omniauth-line-v2_1/tree/v0.0.0
56
+ licenses:
57
+ - MIT
58
+ metadata:
59
+ homepage_uri: https://github.com/cadenza-tech/omniauth-line-v2_1/tree/v0.0.0
60
+ source_code_uri: https://github.com/cadenza-tech/omniauth-line-v2_1/tree/v0.0.0
61
+ changelog_uri: https://github.com/cadenza-tech/omniauth-line-v2_1/blob/v0.0.0/CHANGELOG.md
62
+ bug_tracker_uri: https://github.com/cadenza-tech/omniauth-line-v2_1/issues
63
+ documentation_uri: https://rubydoc.info/gems/omniauth-line-v2_1/0.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 Login v2.1 strategy for OmniAuth
83
+ test_files: []