Skip to content

Commit 843bb42

Browse files
committed
add ID token verification endpoint
1 parent 8760add commit 843bb42

File tree

2 files changed

+30
-0
lines changed

2 files changed

+30
-0
lines changed

lib/line/bot/client.rb

+19
Original file line numberDiff line numberDiff line change
@@ -145,6 +145,25 @@ def revoke_channel_access_token_jwt(access_token)
145145
post(oauth_endpoint, endpoint_path, payload, headers)
146146
end
147147

148+
# Verify ID token
149+
#
150+
# @param id_token [String] ID token
151+
# @param options [Hash] Optional request body
152+
#
153+
# @return [Net::HTTPResponse]
154+
def verify_id_token(id_token, options = {})
155+
channel_id_required
156+
157+
endpoint_path = '/oauth2/v2.1/verify'
158+
payload = URI.encode_www_form(
159+
client_id: channel_id,
160+
id_token: id_token,
161+
**options
162+
)
163+
headers = { 'Content-Type' => 'application/x-www-form-urlencoded' }
164+
post(oauth_endpoint, endpoint_path, payload, headers)
165+
end
166+
148167
# Get all valid channel access token key IDs v2.1
149168
#
150169
# @param jwt [String]

spec/line/bot/client_channel_token_spec.rb

+11
Original file line numberDiff line numberDiff line change
@@ -112,4 +112,15 @@ def generate_client
112112

113113
expect(response).to be_a(Net::HTTPOK)
114114
end
115+
116+
it 'verifies ID token' do
117+
uri_template = Addressable::Template.new Line::Bot::API::DEFAULT_OAUTH_ENDPOINT + '/oauth2/v2.1/verify'
118+
stub_request(:post, uri_template).to_return { |request| {body: '', status: 200} }
119+
120+
client = generate_client
121+
122+
response = client.verify_id_token('dummy_id_token', nonce: 'dummy_nonce')
123+
124+
expect(response).to be_a(Net::HTTPOK)
125+
end
115126
end

0 commit comments

Comments
 (0)