Skip to content

Commit 135f6eb

Browse files
committed
verify_access_token
1 parent ef2ae61 commit 135f6eb

File tree

2 files changed

+32
-0
lines changed

2 files changed

+32
-0
lines changed

lib/line/bot/client.rb

+13
Original file line numberDiff line numberDiff line change
@@ -166,6 +166,19 @@ def verify_id_token(id_token, nonce: nil, user_id: nil)
166166
post(oauth_endpoint, endpoint_path, payload, headers)
167167
end
168168

169+
# Verify access token v2.1
170+
#
171+
# @param access_token [String] access token
172+
#
173+
# @return [Net::HTTPResponse]
174+
def verify_access_token(access_token)
175+
payload = URI.encode_www_form(
176+
access_token: access_token
177+
)
178+
endpoint_path = "/oauth2/v2.1/verify?#{payload}"
179+
get(oauth_endpoint, endpoint_path)
180+
end
181+
169182
# Get all valid channel access token key IDs v2.1
170183
#
171184
# @param jwt [String]

spec/line/bot/client_channel_token_spec.rb

+19
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,14 @@
4747
}
4848
EOS
4949

50+
VERIFY_ACCESS_TOKEN_CONTENT = <<"EOS"
51+
{
52+
"scope": "profile",
53+
"client_id": "1440057261",
54+
"expires_in": 2591659
55+
}
56+
EOS
57+
5058
describe Line::Bot::Client do
5159
def dummy_config
5260
{
@@ -140,4 +148,15 @@ def generate_client
140148

141149
expect(response).to be_a(Net::HTTPOK).and(have_attributes(body: VERIFY_ID_TOKEN_CONTENT))
142150
end
151+
152+
it 'verifies access token' do
153+
uri_template = Addressable::Template.new Line::Bot::API::DEFAULT_OAUTH_ENDPOINT + '/oauth2/v2.1/verify?access_token=dummy_access_token'
154+
stub_request(:get, uri_template).to_return { |request| {body: VERIFY_ACCESS_TOKEN_CONTENT, status: 200} }
155+
156+
client = generate_client
157+
158+
response = client.verify_access_token('dummy_access_token')
159+
160+
expect(response).to be_a(Net::HTTPOK).and(have_attributes(body: VERIFY_ACCESS_TOKEN_CONTENT))
161+
end
143162
end

0 commit comments

Comments
 (0)