Apple-Profil-Link: Token als Query-Parameter
Fastify begrenzt Pfadparameter auf 100 Zeichen (FST_ERR_MAX_PARAM_LENGTH, 414); das Token ist ~140 Zeichen lang. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
parent
0f7cfc2024
commit
1bd76bb5ae
1 changed files with 3 additions and 3 deletions
|
|
@ -24,7 +24,7 @@ const PROFILE_TTL_SEC = 24 * 3600;
|
||||||
const profileSig = (body: string) => createHmac('sha256', config.secretKey).update(`mail-profile:${body}`).digest('base64url');
|
const profileSig = (body: string) => createHmac('sha256', config.secretKey).update(`mail-profile:${body}`).digest('base64url');
|
||||||
const profileLink = (resourceId: string, childId: string, protocol: string) => {
|
const profileLink = (resourceId: string, childId: string, protocol: string) => {
|
||||||
const body = Buffer.from(JSON.stringify({ r: resourceId, c: childId, p: protocol, x: Math.floor(Date.now() / 1000) + PROFILE_TTL_SEC })).toString('base64url');
|
const body = Buffer.from(JSON.stringify({ r: resourceId, c: childId, p: protocol, x: Math.floor(Date.now() / 1000) + PROFILE_TTL_SEC })).toString('base64url');
|
||||||
return `${config.baseUrl}/api/mail-profile/${body}.${profileSig(body)}`;
|
return `${config.baseUrl}/api/mail-profile?t=${body}.${profileSig(body)}`; // Query statt Pfad: Fastify begrenzt Pfadparameter auf 100 Zeichen
|
||||||
};
|
};
|
||||||
function readProfileToken(token: string): { r: string; c: string; p: 'imap' | 'pop3' } | null {
|
function readProfileToken(token: string): { r: string; c: string; p: 'imap' | 'pop3' } | null {
|
||||||
const [body, sig] = token.split('.'); if (!body || !sig) return null;
|
const [body, sig] = token.split('.'); if (!body || !sig) return null;
|
||||||
|
|
@ -266,8 +266,8 @@ export const resourcesModule: KcModule = {
|
||||||
} catch (e) { return providerError(e); }
|
} catch (e) { return providerError(e); }
|
||||||
});
|
});
|
||||||
/** Öffentlich (Token statt Anmeldung): holt das Apple-Profil beim Anbieter und liefert es per https aus. */
|
/** Öffentlich (Token statt Anmeldung): holt das Apple-Profil beim Anbieter und liefert es per https aus. */
|
||||||
app.get('/mail-profile/:token', { config: rl(30, '1 minute') }, async (req, reply) => {
|
app.get('/mail-profile', { config: rl(30, '1 minute') }, async (req, reply) => {
|
||||||
const { token } = z.object({ token: z.string().min(10).max(600) }).parse(req.params);
|
const { t: token } = z.object({ t: z.string().min(10).max(600) }).parse(req.query);
|
||||||
const t = readProfileToken(token); if (!t) throw new AppError(404, 'LINK_INVALID', 'Der Link ist ungültig oder abgelaufen. Bitte die Verbindungsdaten im Kundencenter neu öffnen.');
|
const t = readProfileToken(token); if (!t) throw new AppError(404, 'LINK_INVALID', 'Der Link ist ungültig oder abgelaufen. Bitte die Verbindungsdaten im Kundencenter neu öffnen.');
|
||||||
const r = await loadResource(t.r);
|
const r = await loadResource(t.r);
|
||||||
if (!r || !r.enabled || !childCaps(r).includes('children.read')) throw notFound();
|
if (!r || !r.enabled || !childCaps(r).includes('children.read')) throw notFound();
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue