Skip to content

Commit 368937e

Browse files
Yang-33tokuhirom
andauthored
ChannelAccessToken client doesn't have to require channel access token (#597)
Co-authored-by: Tokuhiro Matsuno <tokuhirom@gmail.com>
1 parent 5119e77 commit 368937e

File tree

5 files changed

+13
-46
lines changed

5 files changed

+13
-46
lines changed

generator/src/main/resources/line-bot-sdk-nodejs-generator/api-single.pebble

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
{# @pebvariable name="imports" type="java.util.List<java.util.Map<String, String>>" #}
22
{# @pebvariable name="operations" type="org.openapitools.codegen.model.OperationMap" #}
3+
{# @pebvariable name="authMethods" type="java.util.ArrayList<org.openapitools.codegen.CodegenSecurity>" -#}
34
{% include "./licenseInfo.pebble" %}
45

56
/* tslint:disable:no-unused-locals */
@@ -19,7 +20,9 @@ import {AxiosResponse} from "axios";
1920

2021
interface httpClientConfig {
2122
baseURL?: string;
23+
{% if authMethods != null -%}
2224
channelAccessToken: string;
25+
{% endif -%}
2326
// TODO support defaultHeaders?
2427
}
2528

@@ -33,7 +36,9 @@ export class {{operations.classname}} {
3336
}
3437
this.httpClient = new HTTPClient({
3538
defaultHeaders: {
39+
{% if authMethods != null -%}
3640
Authorization: "Bearer " + config.channelAccessToken,
41+
{% endif -%}
3742
},
3843
responseParser: this.parseHTTPResponse.bind(this),
3944
baseURL: config.baseURL,

generator/src/main/resources/line-bot-sdk-nodejs-generator/api_test.pebble

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
{# @pebvariable name="imports" type="java.util.List<java.util.Map<String, String>>" #}
22
{# @pebvariable name="operations" type="org.openapitools.codegen.model.OperationMap" #}
3+
{# @pebvariable name="authMethods" type="java.util.ArrayList<org.openapitools.codegen.CodegenSecurity>" -#}
34
import { {{operations.classname}} } from "../../api";
45

56
{% for import in imports -%}
@@ -21,7 +22,9 @@ describe("{{operations.classname}}", () => {
2122
afterEach(() => { server.resetHandlers() })
2223

2324
const client = new {{operations.classname}}({
25+
{% if authMethods != null -%}
2426
channelAccessToken: channel_access_token,
27+
{% endif -%}
2528
});
2629

2730
{% for op in operations.operation %}
@@ -44,10 +47,12 @@ describe("{{operations.classname}}", () => {
4447
({ request, params, cookies }) => {
4548
requestCount++;
4649

50+
{% if authMethods != null -%}
4751
equal(
4852
request.headers.get("Authorization"),
4953
`Bearer ${channel_access_token}`,
5054
);
55+
{% endif -%}
5156
equal(
5257
request.headers.get("User-Agent"),
5358
`${pkg.name}/${pkg.version}`,

lib/channel-access-token/api/channelAccessTokenClient.ts

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,6 @@ import { AxiosResponse } from "axios";
3131

3232
interface httpClientConfig {
3333
baseURL?: string;
34-
channelAccessToken: string;
3534
// TODO support defaultHeaders?
3635
}
3736

@@ -43,9 +42,7 @@ export class ChannelAccessTokenClient {
4342
config.baseURL = "https://api.line.me";
4443
}
4544
this.httpClient = new HTTPClient({
46-
defaultHeaders: {
47-
Authorization: "Bearer " + config.channelAccessToken,
48-
},
45+
defaultHeaders: {},
4946
responseParser: this.parseHTTPResponse.bind(this),
5047
baseURL: config.baseURL,
5148
});

lib/channel-access-token/tests/api/ChannelAccessTokenClientTest.spec.ts

Lines changed: 1 addition & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -27,9 +27,7 @@ describe("ChannelAccessTokenClient", () => {
2727
server.resetHandlers();
2828
});
2929

30-
const client = new ChannelAccessTokenClient({
31-
channelAccessToken: channel_access_token,
32-
});
30+
const client = new ChannelAccessTokenClient({});
3331

3432
it("getsAllValidChannelAccessTokenKeyIds", async () => {
3533
let requestCount = 0;
@@ -42,10 +40,6 @@ describe("ChannelAccessTokenClient", () => {
4240
http.get(endpoint, ({ request, params, cookies }) => {
4341
requestCount++;
4442

45-
equal(
46-
request.headers.get("Authorization"),
47-
`Bearer ${channel_access_token}`,
48-
);
4943
equal(request.headers.get("User-Agent"), `${pkg.name}/${pkg.version}`);
5044

5145
return HttpResponse.json({});
@@ -74,10 +68,6 @@ describe("ChannelAccessTokenClient", () => {
7468
http.post(endpoint, ({ request, params, cookies }) => {
7569
requestCount++;
7670

77-
equal(
78-
request.headers.get("Authorization"),
79-
`Bearer ${channel_access_token}`,
80-
);
8171
equal(request.headers.get("User-Agent"), `${pkg.name}/${pkg.version}`);
8272

8373
return HttpResponse.json({});
@@ -108,10 +98,6 @@ describe("ChannelAccessTokenClient", () => {
10898
http.post(endpoint, ({ request, params, cookies }) => {
10999
requestCount++;
110100

111-
equal(
112-
request.headers.get("Authorization"),
113-
`Bearer ${channel_access_token}`,
114-
);
115101
equal(request.headers.get("User-Agent"), `${pkg.name}/${pkg.version}`);
116102

117103
return HttpResponse.json({});
@@ -144,10 +130,6 @@ describe("ChannelAccessTokenClient", () => {
144130
http.post(endpoint, ({ request, params, cookies }) => {
145131
requestCount++;
146132

147-
equal(
148-
request.headers.get("Authorization"),
149-
`Bearer ${channel_access_token}`,
150-
);
151133
equal(request.headers.get("User-Agent"), `${pkg.name}/${pkg.version}`);
152134

153135
return HttpResponse.json({});
@@ -182,10 +164,6 @@ describe("ChannelAccessTokenClient", () => {
182164
http.post(endpoint, ({ request, params, cookies }) => {
183165
requestCount++;
184166

185-
equal(
186-
request.headers.get("Authorization"),
187-
`Bearer ${channel_access_token}`,
188-
);
189167
equal(request.headers.get("User-Agent"), `${pkg.name}/${pkg.version}`);
190168

191169
return HttpResponse.json({});
@@ -212,10 +190,6 @@ describe("ChannelAccessTokenClient", () => {
212190
http.post(endpoint, ({ request, params, cookies }) => {
213191
requestCount++;
214192

215-
equal(
216-
request.headers.get("Authorization"),
217-
`Bearer ${channel_access_token}`,
218-
);
219193
equal(request.headers.get("User-Agent"), `${pkg.name}/${pkg.version}`);
220194

221195
return HttpResponse.json({});
@@ -246,10 +220,6 @@ describe("ChannelAccessTokenClient", () => {
246220
http.post(endpoint, ({ request, params, cookies }) => {
247221
requestCount++;
248222

249-
equal(
250-
request.headers.get("Authorization"),
251-
`Bearer ${channel_access_token}`,
252-
);
253223
equal(request.headers.get("User-Agent"), `${pkg.name}/${pkg.version}`);
254224

255225
return HttpResponse.json({});
@@ -276,10 +246,6 @@ describe("ChannelAccessTokenClient", () => {
276246
http.get(endpoint, ({ request, params, cookies }) => {
277247
requestCount++;
278248

279-
equal(
280-
request.headers.get("Authorization"),
281-
`Bearer ${channel_access_token}`,
282-
);
283249
equal(request.headers.get("User-Agent"), `${pkg.name}/${pkg.version}`);
284250

285251
return HttpResponse.json({});

test/libs-channelAccessToken.spec.ts

Lines changed: 1 addition & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -5,9 +5,7 @@ import { deepEqual, equal } from "assert";
55

66
const pkg = require("../package.json");
77

8-
const client = new channelAccessToken.ChannelAccessTokenClient({
9-
channelAccessToken: "test_channel_access_token",
10-
});
8+
const client = new channelAccessToken.ChannelAccessTokenClient({});
119

1210
describe("channelAccessToken", () => {
1311
const server = setupServer();
@@ -26,10 +24,6 @@ describe("channelAccessToken", () => {
2624
http.post(
2725
"https://api.line.me/oauth2/v3/token",
2826
async ({ request, params, cookies }) => {
29-
equal(
30-
request.headers.get("Authorization"),
31-
"Bearer test_channel_access_token",
32-
);
3327
equal(
3428
request.headers.get("User-Agent"),
3529
`${pkg.name}/${pkg.version}`,

0 commit comments

Comments
 (0)