feat: start oauth with autoLaunch=1 (#18763)

* Add automatic OpenID Connect login by using parameter `autoLaunch=1`

By launching Immich with `/auth/login?autoLaunch=1` an OpenID Connect login attempt is directly initated on installations where OAuth Auto Launch is not enabled. The intended use for this parameter is to enable Immich to be launched from e.g. Nextcloud using the _External sites_ app and the _oids_ OpenID Connect provider app so as to enable the user to directly interact with Immich without the need to press the `Login with ...` button.

* Add documentation for autolaunch by navigating to `/auth/login?autoLaunch=1`

* Look ma, no braces!

_This could be a single line_

And now it is, as is its predecessor.

* Change formatting to satisfy _prettier_

* if (condition) return true -> return condition

* More _prettier_ reformatting

* Look ma, braces!
This commit is contained in:
Frank de Lange 2025-05-31 00:12:53 +02:00 committed by GitHub
parent f4e4e6628e
commit e2defbc49a
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
3 changed files with 9 additions and 1 deletions

View File

@ -93,6 +93,7 @@ The `.well-known/openid-configuration` part of the url is optional and will be a
## Auto Launch
When Auto Launch is enabled, the login page will automatically redirect the user to the OAuth authorization url, to login with OAuth. To access the login screen again, use the browser's back button, or navigate directly to `/auth/login?autoLaunch=0`.
Auto Launch can also be enabled on a per-request basis by navigating to `/auth/login?authLaunch=1`, this can be useful in situations where Immich is called from e.g. Nextcloud using the _External sites_ app and the _oidc_ app so as to enable users to directly interact with a logged-in instance of Immich.
## Mobile Redirect URI

View File

@ -275,6 +275,10 @@ export const oauth = {
}
return false;
},
isAutoLaunchEnabled: (location: Location) => {
const value = 'autoLaunch=1';
return location.search.includes(value);
},
authorize: async (location: Location) => {
const $t = get(t);
try {

View File

@ -53,7 +53,10 @@
}
try {
if ($featureFlags.oauthAutoLaunch && !oauth.isAutoLaunchDisabled(globalThis.location)) {
if (
($featureFlags.oauthAutoLaunch && !oauth.isAutoLaunchDisabled(globalThis.location)) ||
oauth.isAutoLaunchEnabled(globalThis.location)
) {
await goto(`${AppRoute.AUTH_LOGIN}?autoLaunch=0`, { replaceState: true });
await oauth.authorize(globalThis.location);
return;