Skip to content
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

🐛 Fixes for OpenID with the new config #4530

Merged
merged 2 commits into from
Mar 4, 2025
Merged
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
Original file line number Diff line number Diff line change
Expand Up @@ -134,7 +134,7 @@ export function OpenIdForm({
setLoading(true);
await onSetOpenId({
selectedProvider: providerName,
issuer: issuer ?? '',
discoveryURL: issuer ?? '',
client_id: clientId ?? '',
client_secret: clientSecret ?? '',
server_hostname: serverUrl ?? '',
Expand Down
17 changes: 0 additions & 17 deletions packages/loot-core/src/server/main.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1267,23 +1267,6 @@ handlers['get-openid-config'] = async function () {
}
};

handlers['enable-openid'] = async function (loginConfig) {
try {
const userToken = await asyncStorage.getItem('user-token');

if (!userToken) {
return { error: 'unauthorized' };
}

await post(getServer().BASE_SERVER + '/openid/enable', loginConfig, {
'X-ACTUAL-TOKEN': userToken,
});
} catch (err) {
return { error: err.reason || 'network-failure' };
}
return {};
};

handlers['enable-password'] = async function (loginConfig) {
try {
const userToken = await asyncStorage.getItem('user-token');
Expand Down
3 changes: 2 additions & 1 deletion packages/loot-core/src/types/models/openid.d.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
export type OpenIdConfig = {
selectedProvider: string;
issuer: string;
issuer?: string;
client_id: string;
client_secret: string;
server_hostname: string;
discoveryURL: string;
};
26 changes: 17 additions & 9 deletions packages/sync-server/src/accounts/openid.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ import {
import { TOKEN_EXPIRATION_NEVER } from '../util/validate-user.js';

export async function bootstrapOpenId(configParameter) {
if (!('issuer' in configParameter) || !('discoveryURL' in configParameter)) {
if (!('issuer' in configParameter) && !('discoveryURL' in configParameter)) {
return { error: 'missing-issuer-or-discoveryURL' };
}
if (!('client_id' in configParameter)) {
Expand All @@ -24,6 +24,13 @@ export async function bootstrapOpenId(configParameter) {
}

try {
//FOR BACKWARD COMPATIBLITY:
//If we don't put discoverURL into the issuer, it will break already enabled openid instances
if (configParameter.discoveryURL) {
configParameter.issuer = configParameter.discoveryURL;
delete configParameter.discoveryURL;
}

await setupOpenIdClient(configParameter);
} catch (err) {
console.error('Error setting up OpenID client:', err);
Expand All @@ -49,14 +56,15 @@ export async function bootstrapOpenId(configParameter) {
}

async function setupOpenIdClient(configParameter) {
const issuer = configParameter.discoveryURL
? await Issuer.discover(configParameter.discoveryURL)
: new Issuer({
issuer: configParameter.issuer.name,
authorization_endpoint: configParameter.issuer.authorization_endpoint,
token_endpoint: configParameter.issuer.token_endpoint,
userinfo_endpoint: configParameter.issuer.userinfo_endpoint,
});
const issuer =
typeof configParameter.issuer === 'string'
? await Issuer.discover(configParameter.issuer)
: new Issuer({
issuer: configParameter.issuer.name,
authorization_endpoint: configParameter.issuer.authorization_endpoint,
token_endpoint: configParameter.issuer.token_endpoint,
userinfo_endpoint: configParameter.issuer.userinfo_endpoint,
});

const client = new issuer.Client({
client_id: configParameter.client_id,
Expand Down
6 changes: 6 additions & 0 deletions upcoming-release-notes/4530.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
---
category: Bugfix
authors: [lelemm]
---

Fix for OpenId new variable `ACTUAL_OPENID_DISCOVERY_URL`