1
0
mirror of https://github.com/immich-app/immich.git synced 2024-12-24 10:37:28 +02:00

Api logout route (#361)

* Add logout route that deletes http only cookies

* Rebuild API
This commit is contained in:
Matthias Rupp 2022-07-19 20:49:58 +02:00 committed by GitHub
parent be3e3e5d7e
commit bef1e2e3db
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
13 changed files with 97 additions and 1 deletions

View File

@ -29,6 +29,7 @@ doc/DeviceTypeEnum.md
doc/ExifResponseDto.md
doc/LoginCredentialDto.md
doc/LoginResponseDto.md
doc/LogoutResponseDto.md
doc/RemoveAssetsDto.md
doc/SearchAssetDto.md
doc/ServerInfoApi.md
@ -84,6 +85,7 @@ lib/model/device_type_enum.dart
lib/model/exif_response_dto.dart
lib/model/login_credential_dto.dart
lib/model/login_response_dto.dart
lib/model/logout_response_dto.dart
lib/model/remove_assets_dto.dart
lib/model/search_asset_dto.dart
lib/model/server_info_response_dto.dart
@ -99,3 +101,4 @@ lib/model/user_count_response_dto.dart
lib/model/user_response_dto.dart
lib/model/validate_access_token_response_dto.dart
pubspec.yaml
test/logout_response_dto_test.dart

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

View File

@ -16,6 +16,8 @@ import { SignUpDto } from './dto/sign-up.dto';
import { AdminSignupResponseDto } from './response-dto/admin-signup-response.dto';
import { ValidateAccessTokenResponseDto } from './response-dto/validate-asset-token-response.dto,';
import { Response } from 'express';
import { LogoutResponseDto } from './response-dto/logout-response.dto';
@ApiTags('Authentication')
@Controller('auth')
export class AuthController {
@ -51,4 +53,16 @@ export class AuthController {
async validateAccessToken(@GetAuthUser() authUser: AuthUserDto): Promise<ValidateAccessTokenResponseDto> {
return new ValidateAccessTokenResponseDto(true);
}
@Post('/logout')
async logout(@Res() response: Response): Promise<LogoutResponseDto> {
response.clearCookie('immich_access_token');
response.clearCookie('immich_is_authenticated');
const status = new LogoutResponseDto(true);
response.send(status)
return status;
}
}

View File

@ -0,0 +1,10 @@
import { ApiResponseProperty } from '@nestjs/swagger';
export class LogoutResponseDto {
constructor (successful: boolean) {
this.successful = successful;
}
@ApiResponseProperty()
successful!: boolean;
};

File diff suppressed because one or more lines are too long

View File

@ -782,6 +782,19 @@ export interface LoginResponseDto {
*/
'shouldChangePassword': boolean;
}
/**
*
* @export
* @interface LogoutResponseDto
*/
export interface LogoutResponseDto {
/**
*
* @type {boolean}
* @memberof LogoutResponseDto
*/
'successful': boolean;
}
/**
*
* @export
@ -2885,6 +2898,35 @@ export const AuthenticationApiAxiosParamCreator = function (configuration?: Conf
options: localVarRequestOptions,
};
},
/**
*
* @param {*} [options] Override http request option.
* @throws {RequiredError}
*/
logout: async (options: AxiosRequestConfig = {}): Promise<RequestArgs> => {
const localVarPath = `/auth/logout`;
// use dummy base URL string because the URL constructor only accepts absolute URLs.
const localVarUrlObj = new URL(localVarPath, DUMMY_BASE_URL);
let baseOptions;
if (configuration) {
baseOptions = configuration.baseOptions;
}
const localVarRequestOptions = { method: 'POST', ...baseOptions, ...options};
const localVarHeaderParameter = {} as any;
const localVarQueryParameter = {} as any;
setSearchParams(localVarUrlObj, localVarQueryParameter);
let headersFromBaseOptions = baseOptions && baseOptions.headers ? baseOptions.headers : {};
localVarRequestOptions.headers = {...localVarHeaderParameter, ...headersFromBaseOptions, ...options.headers};
return {
url: toPathString(localVarUrlObj),
options: localVarRequestOptions,
};
},
/**
*
* @param {*} [options] Override http request option.
@ -2948,6 +2990,15 @@ export const AuthenticationApiFp = function(configuration?: Configuration) {
const localVarAxiosArgs = await localVarAxiosParamCreator.login(loginCredentialDto, options);
return createRequestFunction(localVarAxiosArgs, globalAxios, BASE_PATH, configuration);
},
/**
*
* @param {*} [options] Override http request option.
* @throws {RequiredError}
*/
async logout(options?: AxiosRequestConfig): Promise<(axios?: AxiosInstance, basePath?: string) => AxiosPromise<LogoutResponseDto>> {
const localVarAxiosArgs = await localVarAxiosParamCreator.logout(options);
return createRequestFunction(localVarAxiosArgs, globalAxios, BASE_PATH, configuration);
},
/**
*
* @param {*} [options] Override http request option.
@ -2985,6 +3036,14 @@ export const AuthenticationApiFactory = function (configuration?: Configuration,
login(loginCredentialDto: LoginCredentialDto, options?: any): AxiosPromise<LoginResponseDto> {
return localVarFp.login(loginCredentialDto, options).then((request) => request(axios, basePath));
},
/**
*
* @param {*} [options] Override http request option.
* @throws {RequiredError}
*/
logout(options?: any): AxiosPromise<LogoutResponseDto> {
return localVarFp.logout(options).then((request) => request(axios, basePath));
},
/**
*
* @param {*} [options] Override http request option.
@ -3025,6 +3084,16 @@ export class AuthenticationApi extends BaseAPI {
return AuthenticationApiFp(this.configuration).login(loginCredentialDto, options).then((request) => request(this.axios, this.basePath));
}
/**
*
* @param {*} [options] Override http request option.
* @throws {RequiredError}
* @memberof AuthenticationApi
*/
public logout(options?: AxiosRequestConfig) {
return AuthenticationApiFp(this.configuration).logout(options).then((request) => request(this.axios, this.basePath));
}
/**
*
* @param {*} [options] Override http request option.