Skip to content

Commit

Permalink
ChannelAccessToken client doesn't have to require channel access token (
Browse files Browse the repository at this point in the history
#597)

Co-authored-by: Tokuhiro Matsuno <tokuhirom@gmail.com>
  • Loading branch information
Yang-33 and tokuhirom committed Nov 20, 2023
1 parent 5119e77 commit 368937e
Show file tree
Hide file tree
Showing 5 changed files with 13 additions and 46 deletions.
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
{# @pebvariable name="imports" type="java.util.List<java.util.Map<String, String>>" #}
{# @pebvariable name="operations" type="org.openapitools.codegen.model.OperationMap" #}
{# @pebvariable name="authMethods" type="java.util.ArrayList<org.openapitools.codegen.CodegenSecurity>" -#}
{% include "./licenseInfo.pebble" %}

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

interface httpClientConfig {
baseURL?: string;
{% if authMethods != null -%}
channelAccessToken: string;
{% endif -%}
// TODO support defaultHeaders?
}

Expand All @@ -33,7 +36,9 @@ export class {{operations.classname}} {
}
this.httpClient = new HTTPClient({
defaultHeaders: {
{% if authMethods != null -%}
Authorization: "Bearer " + config.channelAccessToken,
{% endif -%}
},
responseParser: this.parseHTTPResponse.bind(this),
baseURL: config.baseURL,
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
{# @pebvariable name="imports" type="java.util.List<java.util.Map<String, String>>" #}
{# @pebvariable name="operations" type="org.openapitools.codegen.model.OperationMap" #}
{# @pebvariable name="authMethods" type="java.util.ArrayList<org.openapitools.codegen.CodegenSecurity>" -#}
import { {{operations.classname}} } from "../../api";

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

const client = new {{operations.classname}}({
{% if authMethods != null -%}
channelAccessToken: channel_access_token,
{% endif -%}
});

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

{% if authMethods != null -%}
equal(
request.headers.get("Authorization"),
`Bearer ${channel_access_token}`,
);
{% endif -%}
equal(
request.headers.get("User-Agent"),
`${pkg.name}/${pkg.version}`,
Expand Down
5 changes: 1 addition & 4 deletions lib/channel-access-token/api/channelAccessTokenClient.ts
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,6 @@ import { AxiosResponse } from "axios";

interface httpClientConfig {
baseURL?: string;
channelAccessToken: string;
// TODO support defaultHeaders?
}

Expand All @@ -43,9 +42,7 @@ export class ChannelAccessTokenClient {
config.baseURL = "https://api.line.me";
}
this.httpClient = new HTTPClient({
defaultHeaders: {
Authorization: "Bearer " + config.channelAccessToken,
},
defaultHeaders: {},
responseParser: this.parseHTTPResponse.bind(this),
baseURL: config.baseURL,
});
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,9 +27,7 @@ describe("ChannelAccessTokenClient", () => {
server.resetHandlers();
});

const client = new ChannelAccessTokenClient({
channelAccessToken: channel_access_token,
});
const client = new ChannelAccessTokenClient({});

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

return HttpResponse.json({});
Expand Down
8 changes: 1 addition & 7 deletions test/libs-channelAccessToken.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,7 @@ import { deepEqual, equal } from "assert";

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

const client = new channelAccessToken.ChannelAccessTokenClient({
channelAccessToken: "test_channel_access_token",
});
const client = new channelAccessToken.ChannelAccessTokenClient({});

describe("channelAccessToken", () => {
const server = setupServer();
Expand All @@ -26,10 +24,6 @@ describe("channelAccessToken", () => {
http.post(
"https://api.line.me/oauth2/v3/token",
async ({ request, params, cookies }) => {
equal(
request.headers.get("Authorization"),
"Bearer test_channel_access_token",
);
equal(
request.headers.get("User-Agent"),
`${pkg.name}/${pkg.version}`,
Expand Down

0 comments on commit 368937e

Please sign in to comment.