fix(server): mobile oauth login (#13474)

This commit is contained in:
Jason Rasmussen 2024-10-15 16:41:19 -04:00 committed by GitHub
parent 7e49b0c875
commit 4c55597478
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
3 changed files with 60 additions and 10 deletions

View file

@ -188,13 +188,13 @@ export class AuthService extends BaseService {
throw new BadRequestException('OAuth is not enabled');
}
const url = await this.oauthRepository.authorize(oauth, dto.redirectUri);
const url = await this.oauthRepository.authorize(oauth, this.resolveRedirectUri(oauth, dto.redirectUri));
return { url };
}
async callback(dto: OAuthCallbackDto, loginDetails: LoginDetails) {
const { oauth } = await this.getConfig({ withCache: false });
const profile = await this.oauthRepository.getProfile(oauth, dto.url, this.normalize(oauth, dto.url.split('?')[0]));
const profile = await this.oauthRepository.getProfile(oauth, dto.url, this.resolveRedirectUri(oauth, dto.url));
const { autoRegister, defaultStorageQuota, storageLabelClaim, storageQuotaClaim } = oauth;
this.logger.debug(`Logging in with OAuth: ${JSON.stringify(profile)}`);
let user = await this.userRepository.getByOAuthId(profile.sub);
@ -257,7 +257,7 @@ export class AuthService extends BaseService {
const { sub: oauthId } = await this.oauthRepository.getProfile(
oauth,
dto.url,
this.normalize(oauth, dto.url.split('?')[0]),
this.resolveRedirectUri(oauth, dto.url),
);
const duplicate = await this.userRepository.getByOAuthId(oauthId);
if (duplicate && duplicate.id !== auth.user.id) {
@ -369,10 +369,11 @@ export class AuthService extends BaseService {
return options.isValid(value) ? (value as T) : options.default;
}
private normalize(
private resolveRedirectUri(
{ mobileRedirectUri, mobileOverrideEnabled }: { mobileRedirectUri: string; mobileOverrideEnabled: boolean },
redirectUri: string,
url: string,
) {
const redirectUri = url.split('?')[0];
const isMobile = redirectUri.startsWith('app.immich:/');
if (isMobile && mobileOverrideEnabled && mobileRedirectUri) {
return mobileRedirectUri;