Skip to content

Commit ee676ac

Browse files
committed
Fix invalid api path and test
1 parent 01d52ce commit ee676ac

File tree

3 files changed

+14
-9
lines changed

3 files changed

+14
-9
lines changed

lib/line/bot/api.rb

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@
1717
module Line
1818
module Bot
1919
module API
20+
DEFAULT_OAUTH_ENDPOINT = "https://api.line.me"
2021
DEFAULT_ENDPOINT = "https://api.line.me/v2"
2122
DEFAULT_BLOB_ENDPOINT = "https://api-data.line.me/v2"
2223
DEFAULT_LIFF_ENDPOINT = "https://api.line.me/liff/v1"

lib/line/bot/client.rb

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,10 @@ def endpoint
5555
@endpoint ||= API::DEFAULT_ENDPOINT
5656
end
5757

58+
def oauth_endpoint
59+
@oauth_endpoint ||= API::DEFAULT_OAUTH_ENDPOINT
60+
end
61+
5862
def blob_endpoint
5963
return @blob_endpoint if @blob_endpoint
6064

@@ -122,7 +126,7 @@ def issue_channel_access_token_21(jwt)
122126
client_assertion: jwt
123127
)
124128
headers = { 'Content-Type' => 'application/x-www-form-urlencoded' }
125-
post(endpoint, endpoint_path, payload, headers)
129+
post(oauth_endpoint, endpoint_path, payload, headers)
126130
end
127131

128132
# Revoke channel access token v2.1
@@ -141,7 +145,7 @@ def revoke_channel_access_token_21(access_token)
141145
access_token: access_token
142146
)
143147
headers = { 'Content-Type' => 'application/x-www-form-urlencoded' }
144-
post(endpoint, endpoint_path, payload, headers)
148+
post(oauth_endpoint, endpoint_path, payload, headers)
145149
end
146150

147151
# Get all valid channel access token key IDs v2.1
@@ -153,14 +157,14 @@ def get_channel_access_token_key_ids_21(jwt)
153157
channel_id_required
154158
channel_secret_required
155159

156-
endpoint_path = '/oauth2/v2.1/tokens/kid'
157160
payload = URI.encode_www_form(
158-
grant_type: 'client_credentials',
159161
client_assertion_type: 'urn:ietf:params:oauth:client-assertion-type:jwt-bearer',
160162
client_assertion: jwt
161163
)
164+
endpoint_path = "/oauth2/v2.1/tokens/kid?#{payload}"
165+
162166
headers = { 'Content-Type' => 'application/x-www-form-urlencoded' }
163-
post(endpoint, endpoint_path, payload, headers)
167+
get(oauth_endpoint, endpoint_path, headers)
164168
end
165169

166170
# Push messages to a user using user_id.

spec/line/bot/client_channel_token_spec.rb

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -73,7 +73,7 @@ def generate_client
7373
end
7474

7575
it 'issues an oauth access token v2.1' do
76-
uri_template = Addressable::Template.new Line::Bot::API::DEFAULT_ENDPOINT + '/oauth2/v2.1/token'
76+
uri_template = Addressable::Template.new Line::Bot::API::DEFAULT_OAUTH_ENDPOINT + '/oauth2/v2.1/token'
7777
stub_request(:post, uri_template).to_return { |request| {body: ISSUE_CHANNEL_ACCESS_TOKEN_21_CONTENT, status: 200} }
7878

7979
client = generate_client
@@ -88,7 +88,7 @@ def generate_client
8888
end
8989

9090
it 'revokes the oauth access token v2.1' do
91-
uri_template = Addressable::Template.new Line::Bot::API::DEFAULT_ENDPOINT + '/oauth2/v2.1/revoke'
91+
uri_template = Addressable::Template.new Line::Bot::API::DEFAULT_OAUTH_ENDPOINT + '/oauth2/v2.1/revoke'
9292
stub_request(:post, uri_template).to_return { |request| {body: '', status: 200} }
9393

9494
client = generate_client
@@ -99,8 +99,8 @@ def generate_client
9999
end
100100

101101
it 'get all valid channel access token key ids v2.1' do
102-
uri_template = Addressable::Template.new Line::Bot::API::DEFAULT_ENDPOINT + '/oauth2/v2.1/tokens/kid'
103-
stub_request(:post, uri_template).to_return { |request| {body: GET_CHANNEL_ACCESS_TOKEN_KEY_IDS_21_CONTENT, status: 200} }
102+
uri_template = Addressable::Template.new Line::Bot::API::DEFAULT_OAUTH_ENDPOINT + "/oauth2/v2.1/tokens/kid?client_assertion=jwt_string&client_assertion_type=urn:ietf:params:oauth:client-assertion-type:jwt-bearer"
103+
stub_request(:any, uri_template).to_return { |request| {body: GET_CHANNEL_ACCESS_TOKEN_KEY_IDS_21_CONTENT, status: 200} }
104104

105105
client = generate_client
106106

0 commit comments

Comments
 (0)