Skip to content

Commit ef2ae61

Browse files
committed
make argument of verify_id_token more explicit
1 parent 843bb42 commit ef2ae61

File tree

2 files changed

+26
-7
lines changed

2 files changed

+26
-7
lines changed

lib/line/bot/client.rb

+7-5
Original file line numberDiff line numberDiff line change
@@ -148,18 +148,20 @@ def revoke_channel_access_token_jwt(access_token)
148148
# Verify ID token
149149
#
150150
# @param id_token [String] ID token
151-
# @param options [Hash] Optional request body
151+
# @param nonce [String] Expected nonce value. Use the nonce value provided in the authorization request. Omit if the nonce value was not specified in the authorization request.
152+
# @param user_id [String] Expected user ID.
152153
#
153154
# @return [Net::HTTPResponse]
154-
def verify_id_token(id_token, options = {})
155+
def verify_id_token(id_token, nonce: nil, user_id: nil)
155156
channel_id_required
156157

157158
endpoint_path = '/oauth2/v2.1/verify'
158-
payload = URI.encode_www_form(
159+
payload = URI.encode_www_form({
159160
client_id: channel_id,
160161
id_token: id_token,
161-
**options
162-
)
162+
nonce: nonce,
163+
user_id: user_id
164+
}.compact)
163165
headers = { 'Content-Type' => 'application/x-www-form-urlencoded' }
164166
post(oauth_endpoint, endpoint_path, payload, headers)
165167
end

spec/line/bot/client_channel_token_spec.rb

+19-2
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,21 @@
3232
}
3333
EOS
3434

35+
VERIFY_ID_TOKEN_CONTENT = <<"EOS"
36+
{
37+
"iss": "https://access.line.me",
38+
"sub": "U1234567890abcdef1234567890abcdef",
39+
"aud": "1234567890",
40+
"exp": 1504169092,
41+
"iat": 1504263657,
42+
"nonce": "0987654asdf",
43+
"amr": ["pwd"],
44+
"name": "Taro Line",
45+
"picture": "https://sample_line.me/aBcdefg123456",
46+
"email": "[email protected]"
47+
}
48+
EOS
49+
3550
describe Line::Bot::Client do
3651
def dummy_config
3752
{
@@ -115,12 +130,14 @@ def generate_client
115130

116131
it 'verifies ID token' do
117132
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} }
133+
stub_request(:post, uri_template)
134+
.with(body: { client_id: 'channel id', id_token: 'dummy_id_token', nonce: 'dummy_nonce'})
135+
.to_return { |request| {body: VERIFY_ID_TOKEN_CONTENT, status: 200} }
119136

120137
client = generate_client
121138

122139
response = client.verify_id_token('dummy_id_token', nonce: 'dummy_nonce')
123140

124-
expect(response).to be_a(Net::HTTPOK)
141+
expect(response).to be_a(Net::HTTPOK).and(have_attributes(body: VERIFY_ID_TOKEN_CONTENT))
125142
end
126143
end

0 commit comments

Comments
 (0)