line_login 0.1.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/README.md +78 -0
- data/Rakefile +6 -0
- data/lib/line_login/client.rb +178 -0
- data/lib/line_login/version.rb +5 -0
- data/lib/line_login.rb +4 -0
- metadata +118 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA256:
|
3
|
+
metadata.gz: 631de5088443f630a2563f89c5c311edcb98fc384ba7d1f545b958e98e64109e
|
4
|
+
data.tar.gz: 227520805ea4b7eaefc94c883239f6e6eb8d83f78c65c08fda00fb4c7676c6b4
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: 1a7cab9d6648aba29df4edd2a983f8b82053d309553a2e92ca916d3f2bda35bcc37c68c0d60112173bf93504f3a9064d73e7e36ac01246cce8b62398ab8ccc94
|
7
|
+
data.tar.gz: a900cc24fb2c84fcd7629efc65aaa66b64206cbc63189aea2ff452e265ef9a4072d14c14aae027ae3118f6df1e495a3586b6b0fbde3e59c1729028695da80e13
|
data/README.md
ADDED
@@ -0,0 +1,78 @@
|
|
1
|
+
# LINE Login
|
2
|
+
|
3
|
+
LINE Login is a [LINE Login 2.1](https://developers.line.biz/en/reference/line-login/) Client for Ruby.
|
4
|
+
|
5
|
+
## Installation
|
6
|
+
|
7
|
+
Add the following code to your application's Gemfile:
|
8
|
+
|
9
|
+
```ruby
|
10
|
+
gem 'line_login'
|
11
|
+
```
|
12
|
+
|
13
|
+
And then execute:
|
14
|
+
|
15
|
+
$ bundle
|
16
|
+
|
17
|
+
Or install it yourself as:
|
18
|
+
|
19
|
+
$ gem install line_login
|
20
|
+
|
21
|
+
## Usage
|
22
|
+
|
23
|
+
### initialize client instance
|
24
|
+
|
25
|
+
```ruby
|
26
|
+
client = LineLogin::Client.new(
|
27
|
+
client_id: "your line login client id",
|
28
|
+
client_secret: "your line login client secret",
|
29
|
+
redirect_uri: "your redirect uri"
|
30
|
+
)
|
31
|
+
```
|
32
|
+
|
33
|
+
### get auth link
|
34
|
+
|
35
|
+
Describe all parameters of this method in [the LINE Login documentation](https://developers.line.biz/en/docs/line-login/integrate-line-login/#making-an-authorization-request).
|
36
|
+
|
37
|
+
There are no required parameters, the default value of scope is `profile%20openid%20email`, and state is `state`.
|
38
|
+
|
39
|
+
```ruby
|
40
|
+
auth_link = client.get_auth_link
|
41
|
+
```
|
42
|
+
|
43
|
+
You can override any parameter by passing it.
|
44
|
+
|
45
|
+
```ruby
|
46
|
+
auth_link = client.get_auth_link(scope: "", state: "state")
|
47
|
+
```
|
48
|
+
|
49
|
+
### get access token
|
50
|
+
|
51
|
+
```ruby
|
52
|
+
code = "you can get code from redirect uri after user click the auth link"
|
53
|
+
token = client.get_access_token(code)
|
54
|
+
```
|
55
|
+
|
56
|
+
|
57
|
+
### revoke access token
|
58
|
+
|
59
|
+
```
|
60
|
+
response = client.revoke(token)
|
61
|
+
```
|
62
|
+
|
63
|
+
## Testing
|
64
|
+
|
65
|
+
Type the following command in your terminal to run the tests:
|
66
|
+
|
67
|
+
```
|
68
|
+
rake spec
|
69
|
+
```
|
70
|
+
|
71
|
+
## Contributing
|
72
|
+
|
73
|
+
Bug reports and pull requests are welcome on GitHub at https://github.com/etrex/line_login.
|
74
|
+
|
75
|
+
## License
|
76
|
+
|
77
|
+
The gem is available as open source under the terms of the [MIT License](https://opensource.org/licenses/MIT).
|
78
|
+
|
data/Rakefile
ADDED
@@ -0,0 +1,178 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require "net/http"
|
4
|
+
require "json"
|
5
|
+
|
6
|
+
module LineLogin
|
7
|
+
class Client
|
8
|
+
attr_accessor :client_id
|
9
|
+
attr_accessor :client_secret
|
10
|
+
attr_accessor :redirect_uri
|
11
|
+
attr_accessor :api_origin
|
12
|
+
attr_accessor :access_origin
|
13
|
+
|
14
|
+
def initialize(client_id: "client_id", client_secret: "client_secret", redirect_uri: "redirect_uri", api_origin: "https://api.line.me", access_origin: "https://access.line.me")
|
15
|
+
self.client_id = client_id
|
16
|
+
self.client_secret = client_secret
|
17
|
+
self.redirect_uri = redirect_uri
|
18
|
+
self.api_origin = api_origin
|
19
|
+
self.access_origin = access_origin
|
20
|
+
end
|
21
|
+
|
22
|
+
# Get Auth Link
|
23
|
+
#
|
24
|
+
# Authenticating users and making authorization requests
|
25
|
+
#
|
26
|
+
# Initiate the process of authenticating the user with the LINE Platform and authorizing your app.
|
27
|
+
# When the user clicks a LINE Login button, redirect them to an authorization URL with the required query parameters,
|
28
|
+
# as shown in the example below.
|
29
|
+
#
|
30
|
+
def get_auth_link(options = {})
|
31
|
+
data = {
|
32
|
+
scope: "profile%20openid%20email",
|
33
|
+
response_type: "code",
|
34
|
+
client_id: self.client_id,
|
35
|
+
redirect_uri: self.redirect_uri,
|
36
|
+
state: "state"
|
37
|
+
}.merge(options);
|
38
|
+
"#{self.access_origin}/oauth2/v2.1/authorize?#{URI.encode_www_form(data)}"
|
39
|
+
end
|
40
|
+
|
41
|
+
# Issues access tokens.
|
42
|
+
#
|
43
|
+
# The access tokens managed through the LINE Login API attest that an app has been granted permission to access user data
|
44
|
+
# (such as user IDs, display names, profile images, and status messages) saved on the LINE Platform.
|
45
|
+
#
|
46
|
+
# LINE Login API calls require you to provide an access token or refresh token that was sent in an earlier response.
|
47
|
+
def issue_access_token(code: , redirect_uri: nil, code_verifier: nil)
|
48
|
+
option = {
|
49
|
+
url: "#{api_origin}/oauth2/v2.1/token",
|
50
|
+
header: {
|
51
|
+
"Content-Type": "application/x-www-form-urlencoded",
|
52
|
+
},
|
53
|
+
param: {
|
54
|
+
grant_type: :authorization_code,
|
55
|
+
code: code,
|
56
|
+
redirect_uri: redirect_uri || self.redirect_uri,
|
57
|
+
client_id: client_id,
|
58
|
+
client_secret: client_secret,
|
59
|
+
code_verifier: code_verifier
|
60
|
+
}
|
61
|
+
}
|
62
|
+
response = post(option)
|
63
|
+
JSON.parse(response.body)
|
64
|
+
end
|
65
|
+
|
66
|
+
# Verifies if an access token is valid.
|
67
|
+
#
|
68
|
+
# For general recommendations on how to securely handle user registration and login with access tokens,
|
69
|
+
# see Creating a secure login process between your app and server in the LINE Login documentation.
|
70
|
+
#
|
71
|
+
def verify_access_token(access_token: )
|
72
|
+
option = {
|
73
|
+
url: "#{api_origin}/oauth2/v2.1/verify?access_token=#{access_token}",
|
74
|
+
}
|
75
|
+
response = get(option)
|
76
|
+
JSON.parse(response.body)
|
77
|
+
end
|
78
|
+
|
79
|
+
# Refresh access token
|
80
|
+
#
|
81
|
+
# Gets a new access token using a refresh token.
|
82
|
+
# A refresh token is returned along with an access token once user authentication is complete.
|
83
|
+
#
|
84
|
+
def refresh_access_token(refresh_token: )
|
85
|
+
option = {
|
86
|
+
url: "#{api_origin}/oauth2/v2.1/token",
|
87
|
+
header: {
|
88
|
+
"Content-Type": "application/x-www-form-urlencoded",
|
89
|
+
},
|
90
|
+
param: {
|
91
|
+
grant_type: :refresh_token,
|
92
|
+
refresh_token: refresh_token,
|
93
|
+
client_id: client_id,
|
94
|
+
client_secret: client_secret
|
95
|
+
}
|
96
|
+
}
|
97
|
+
response = post(option)
|
98
|
+
JSON.parse(response.body)
|
99
|
+
end
|
100
|
+
|
101
|
+
# Revoke access token
|
102
|
+
#
|
103
|
+
# Invalidates a user's access token.
|
104
|
+
#
|
105
|
+
def revoke_access_token(access_token: )
|
106
|
+
option = {
|
107
|
+
url: "#{api_origin}/oauth2/v2.1/revoke",
|
108
|
+
header: {
|
109
|
+
"Content-Type": "application/x-www-form-urlencoded",
|
110
|
+
},
|
111
|
+
param: {
|
112
|
+
access_token: access_token,
|
113
|
+
client_id: client_id,
|
114
|
+
client_secret: client_secret
|
115
|
+
}
|
116
|
+
}
|
117
|
+
response = post(option)
|
118
|
+
response.body
|
119
|
+
end
|
120
|
+
|
121
|
+
# Verify ID token
|
122
|
+
#
|
123
|
+
# ID tokens are JSON web tokens (JWT) with information about the user.
|
124
|
+
# It's possible for an attacker to spoof an ID token.
|
125
|
+
# Use this call to verify that a received ID token is authentic,
|
126
|
+
# meaning you can use it to obtain the user's profile information and email.
|
127
|
+
#
|
128
|
+
def verify_id_token(id_token: , nonce: nil, user_id: nil)
|
129
|
+
param = {
|
130
|
+
id_token: id_token,
|
131
|
+
client_id: client_id
|
132
|
+
}
|
133
|
+
param[:nonce] = nonce unless nonce.nil?
|
134
|
+
param[:user_id] = user_id unless user_id.nil?
|
135
|
+
|
136
|
+
option = {
|
137
|
+
url: "#{api_origin}/oauth2/v2.1/verify",
|
138
|
+
header: {
|
139
|
+
"Content-Type": "application/x-www-form-urlencoded",
|
140
|
+
},
|
141
|
+
param: param
|
142
|
+
}
|
143
|
+
response = post(option)
|
144
|
+
JSON.parse(response.body)
|
145
|
+
end
|
146
|
+
|
147
|
+
private
|
148
|
+
|
149
|
+
# 發送一個get
|
150
|
+
# option: :url, :header, :param, :ssl_verify
|
151
|
+
def get(option)
|
152
|
+
url = URI(option[:url])
|
153
|
+
http = Net::HTTP.new(url.host, url.port)
|
154
|
+
http.use_ssl = option[:url]["https://"].nil? == false
|
155
|
+
http.verify_mode = OpenSSL::SSL::VERIFY_NONE unless option[:ssl_verify]
|
156
|
+
request = Net::HTTP::Get.new(url)
|
157
|
+
option[:header]&.each do |key, value|
|
158
|
+
request[key] = value
|
159
|
+
end
|
160
|
+
http.request(request)
|
161
|
+
end
|
162
|
+
|
163
|
+
# 發送一個post
|
164
|
+
# option: :url, :header, :param, :ssl_verify
|
165
|
+
def post(option)
|
166
|
+
url = URI(option[:url])
|
167
|
+
http = Net::HTTP.new(url.host, url.port)
|
168
|
+
http.use_ssl = option[:url]["https://"].nil? == false
|
169
|
+
http.verify_mode = OpenSSL::SSL::VERIFY_NONE unless option[:ssl_verify]
|
170
|
+
request = Net::HTTP::Post.new(url)
|
171
|
+
option[:header]&.each do |key, value|
|
172
|
+
request[key] = value
|
173
|
+
end
|
174
|
+
request.set_form_data(option[:param] || {})
|
175
|
+
http.request(request)
|
176
|
+
end
|
177
|
+
end
|
178
|
+
end
|
data/lib/line_login.rb
ADDED
metadata
ADDED
@@ -0,0 +1,118 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: line_login
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.1.0
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- etrex kuo
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
date: 2022-01-09 00:00:00.000000000 Z
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: bundler
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - ">="
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: '1.17'
|
20
|
+
type: :development
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - ">="
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: '1.17'
|
27
|
+
- !ruby/object:Gem::Dependency
|
28
|
+
name: rake
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - ">="
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: '13.0'
|
34
|
+
type: :development
|
35
|
+
prerelease: false
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - ">="
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: '13.0'
|
41
|
+
- !ruby/object:Gem::Dependency
|
42
|
+
name: rspec
|
43
|
+
requirement: !ruby/object:Gem::Requirement
|
44
|
+
requirements:
|
45
|
+
- - ">="
|
46
|
+
- !ruby/object:Gem::Version
|
47
|
+
version: '3.0'
|
48
|
+
type: :development
|
49
|
+
prerelease: false
|
50
|
+
version_requirements: !ruby/object:Gem::Requirement
|
51
|
+
requirements:
|
52
|
+
- - ">="
|
53
|
+
- !ruby/object:Gem::Version
|
54
|
+
version: '3.0'
|
55
|
+
- !ruby/object:Gem::Dependency
|
56
|
+
name: webmock
|
57
|
+
requirement: !ruby/object:Gem::Requirement
|
58
|
+
requirements:
|
59
|
+
- - ">="
|
60
|
+
- !ruby/object:Gem::Version
|
61
|
+
version: '0'
|
62
|
+
type: :development
|
63
|
+
prerelease: false
|
64
|
+
version_requirements: !ruby/object:Gem::Requirement
|
65
|
+
requirements:
|
66
|
+
- - ">="
|
67
|
+
- !ruby/object:Gem::Version
|
68
|
+
version: '0'
|
69
|
+
- !ruby/object:Gem::Dependency
|
70
|
+
name: json
|
71
|
+
requirement: !ruby/object:Gem::Requirement
|
72
|
+
requirements:
|
73
|
+
- - ">="
|
74
|
+
- !ruby/object:Gem::Version
|
75
|
+
version: '0'
|
76
|
+
type: :runtime
|
77
|
+
prerelease: false
|
78
|
+
version_requirements: !ruby/object:Gem::Requirement
|
79
|
+
requirements:
|
80
|
+
- - ">="
|
81
|
+
- !ruby/object:Gem::Version
|
82
|
+
version: '0'
|
83
|
+
description: Line Login 2.1 Client for Ruby
|
84
|
+
email:
|
85
|
+
- et284vu065k3@gmail.com
|
86
|
+
executables: []
|
87
|
+
extensions: []
|
88
|
+
extra_rdoc_files: []
|
89
|
+
files:
|
90
|
+
- README.md
|
91
|
+
- Rakefile
|
92
|
+
- lib/line_login.rb
|
93
|
+
- lib/line_login/client.rb
|
94
|
+
- lib/line_login/version.rb
|
95
|
+
homepage: https://github.com/etrex/line_login
|
96
|
+
licenses:
|
97
|
+
- MIT
|
98
|
+
metadata: {}
|
99
|
+
post_install_message:
|
100
|
+
rdoc_options: []
|
101
|
+
require_paths:
|
102
|
+
- lib
|
103
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
104
|
+
requirements:
|
105
|
+
- - ">="
|
106
|
+
- !ruby/object:Gem::Version
|
107
|
+
version: '0'
|
108
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
109
|
+
requirements:
|
110
|
+
- - ">="
|
111
|
+
- !ruby/object:Gem::Version
|
112
|
+
version: '0'
|
113
|
+
requirements: []
|
114
|
+
rubygems_version: 3.1.6
|
115
|
+
signing_key:
|
116
|
+
specification_version: 4
|
117
|
+
summary: Line Login 2.1 Client
|
118
|
+
test_files: []
|