Skip to content

Commit b8bbf24

Browse files
committed
Add SessionAuthentication API
1 parent 42e38cc commit b8bbf24

File tree

3 files changed

+132
-0
lines changed

3 files changed

+132
-0
lines changed
Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,54 @@
1+
import nock from "nock";
2+
import { createClient } from "../__mocks__/base";
3+
import SessionAuthenticationApi from "../services/sessionAuthentication";
4+
import Client from "../client";
5+
import { AuthenticationSessionRequest, AuthenticationSessionResponse, ProductType, ResourceType } from "../typings/sessionAuthentication/models";
6+
7+
let client: Client;
8+
let sessionAuthenticationApi: SessionAuthenticationApi;
9+
let scope: nock.Scope;
10+
11+
beforeEach((): void => {
12+
if (!nock.isActive()) {
13+
nock.activate();
14+
}
15+
client = createClient();
16+
sessionAuthenticationApi = new SessionAuthenticationApi(client);
17+
scope = nock("https://test.adyen.com/authe/api/v1");
18+
});
19+
20+
afterEach(() => {
21+
nock.cleanAll();
22+
});
23+
24+
describe("SessionAuthenticationApi", (): void => {
25+
test("should create an authentication session", async (): Promise<void> => {
26+
const mockResponse: AuthenticationSessionResponse = {
27+
id: "12345678",
28+
token: "ABCDEFGHIJKLMNOP",
29+
};
30+
31+
scope.post("/sessions").reply(200, mockResponse);
32+
33+
const accountHolderResource = {
34+
type: ResourceType.AccountHolder,
35+
accountHolderId: "accountHolder1"
36+
};
37+
38+
const request: AuthenticationSessionRequest = {
39+
allowOrigin: "https://your-merchant-website.com",
40+
policy: {
41+
resources: new Set([
42+
accountHolderResource
43+
]),
44+
roles: new Set(["role1", "role2"])
45+
},
46+
product: ProductType.Platform
47+
};
48+
49+
const result = await sessionAuthenticationApi.SessionAuthenticationApi.createAuthenticationSession(request);
50+
51+
expect(result).toBeTruthy();
52+
expect(result.token).toBe("ABCDEFGHIJKLMNOP");
53+
});
54+
});
Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
/*
2+
* The version of the OpenAPI document: v1
3+
*
4+
*
5+
* NOTE: This class is auto generated by OpenAPI Generator (https://openapi-generator.tech).
6+
* https://openapi-generator.tech
7+
* Do not edit this class manually.
8+
*/
9+
10+
import { SessionAuthenticationApi } from "./sessionAuthenticationApi";
11+
12+
import Service from "../../service";
13+
import Client from "../../client";
14+
15+
export default class SessionAuthenticationAPI extends Service {
16+
17+
public constructor(client: Client) {
18+
super(client);
19+
}
20+
21+
public get SessionAuthenticationApi() {
22+
return new SessionAuthenticationApi(this.client);
23+
}
24+
}
Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,54 @@
1+
/*
2+
* The version of the OpenAPI document: v1
3+
*
4+
*
5+
* NOTE: This class is auto generated by OpenAPI Generator (https://openapi-generator.tech).
6+
* https://openapi-generator.tech
7+
* Do not edit this class manually.
8+
*/
9+
10+
11+
import getJsonResponse from "../../helpers/getJsonResponse";
12+
import Service from "../../service";
13+
import Client from "../../client";
14+
import { IRequest } from "../../typings/requestOptions";
15+
import Resource from "../resource";
16+
17+
import { ObjectSerializer } from "../../typings/sessionAuthentication/objectSerializer";
18+
import { AuthenticationSessionRequest } from "../../typings/sessionAuthentication/models";
19+
import { AuthenticationSessionResponse } from "../../typings/sessionAuthentication/models";
20+
21+
/**
22+
* API handler for SessionAuthenticationApi
23+
*/
24+
export class SessionAuthenticationApi extends Service {
25+
26+
private readonly API_BASEPATH: string = "https://test.adyen.com/authe/api/v1";
27+
private baseUrl: string;
28+
29+
public constructor(client: Client){
30+
super(client);
31+
this.baseUrl = this.createBaseUrl(this.API_BASEPATH);
32+
}
33+
34+
/**
35+
* @summary Create a session token
36+
* @param authenticationSessionRequest {@link AuthenticationSessionRequest }
37+
* @param requestOptions {@link IRequest.Options }
38+
* @return {@link AuthenticationSessionResponse }
39+
*/
40+
public async createAuthenticationSession(authenticationSessionRequest: AuthenticationSessionRequest, requestOptions?: IRequest.Options): Promise<AuthenticationSessionResponse> {
41+
const endpoint = `${this.baseUrl}/sessions`;
42+
const resource = new Resource(this, endpoint);
43+
44+
const request: AuthenticationSessionRequest = ObjectSerializer.serialize(authenticationSessionRequest, "AuthenticationSessionRequest", "");
45+
const response = await getJsonResponse<AuthenticationSessionRequest, AuthenticationSessionResponse>(
46+
resource,
47+
request,
48+
{ ...requestOptions, method: "POST" }
49+
);
50+
51+
return ObjectSerializer.deserialize(response, "AuthenticationSessionResponse", "");
52+
}
53+
54+
}

0 commit comments

Comments
 (0)