Skip to content

Add support for session revoke #1104

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
26 changes: 26 additions & 0 deletions src/management/__generated/managers/sessions-manager.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import type { InitOverride, ApiResponse } from '../../../lib/runtime.js';
import type {
GetSession200Response,
DeleteSessionRequest,
RevokeSessionRequest,
GetSessionRequest,
} from '../models/index.js';

Expand Down Expand Up @@ -35,6 +36,31 @@ export class SessionsManager extends BaseAPI {
return runtime.VoidApiResponse.fromResponse(response);
}

/**
* Revokes a session by ID and all associated refresh tokens.
*
* @throws {RequiredError}
*/
async revoke(
requestParameters: RevokeSessionRequest,
initOverrides?: InitOverride
): Promise<ApiResponse<void>> {
runtime.validateRequiredRequestParams(requestParameters, ['id']);

const response = await this.request(
{
path: `/sessions/{id}/revoke`.replace(
'{id}',
encodeURIComponent(String(requestParameters.id))
),
method: 'POST',
},
initOverrides
);

return runtime.VoidApiResponse.fromResponse(response);
}

/**
* Retrieve session information.
* Get session
Expand Down
10 changes: 10 additions & 0 deletions src/management/__generated/models/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21213,6 +21213,16 @@ export interface DeleteSessionRequest {
*/
id: string;
}
/**
*
*/
export interface RevokeSessionRequest {
/**
* ID of the session to revoke.
*
*/
id: string;
}
/**
*
*/
Expand Down
48 changes: 48 additions & 0 deletions test/management/sessions.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -133,6 +133,54 @@ describe('SessionsManager', () => {
sessions.delete({ id }).then(() => {
expect(request.isDone()).toBe(true);

done();
});
});
});
describe('#revoke', () => {
const id = '6';

let request: nock.Scope;

beforeEach(() => {
request = nock(API_URL).post(`/sessions/${id}/revoke`).reply(200, {});
});

it('should return a promise when no callback is given', (done) => {
sessions.revoke({ id }).then(done.bind(null, null));
});

it(`should perform a revoke request to /sessions/${id}/revoke`, (done) => {
sessions.revoke({ id }).then(() => {
expect(request.isDone()).toBe(true);

done();
});
});

it('should pass any errors to the promise catch handler', (done) => {
nock.cleanAll();

nock(API_URL).post(`/sessions/${id}/revoke`).reply(500, {});

sessions.revoke({ id }).catch((err) => {
expect(err).toBeDefined();

done();
});
});

it('should include the token in the authorization header', (done) => {
nock.cleanAll();

const request = nock(API_URL)
.post(`/sessions/${id}/revoke`)
.matchHeader('authorization', `Bearer ${token}`)
.reply(200, {});

sessions.revoke({ id }).then(() => {
expect(request.isDone()).toBe(true);

done();
});
});
Expand Down