A session key identifies a portal user (a Contact) on every request. A magic link is a separate, emailable token that the portal exchanges for a session key. There is no Salesforce User login for portal users. With Secure Session Keys enabled in 12.5, both tokens are signed by the org that issued them. The setting is off by default; the rollout steps below describe legacy compatibility.
With Secure Session Keys enabled in 12.5, a session key or magic link token is an opaque, signed value that is safe to place in a URL as is. Treat it as a credential. Do not parse it, store it or build logic on its contents. To find out who a key belongs to, call b3p.PortalSession (see Verifying a session from another package).
The signing key is generated inside each org. It is not shipped in the package and is not visible to admins, code or the API.
Validity is Portal_Magic_Link_Validity__c days (default 14) unless the caller supplies its own. Link validity and session length are two different controls. See Capping session length.
The legacy token format is deprecated. Enable Secure Session Keys on every org as soon as your installed packages support it.
Everything this article says about signed tokens applies once Secure Session Keys (Secure_Session_Keys__c) is checked on the Portal custom setting. Its default is unchecked so that other 3B packages keep working during migration. Configure it on the effective Portal settings records, including any Site guest user or profile overrides. While it is unchecked:
Expire_Session_Keys__c checked, set a session length cap and check One Time Magic Links until you switch to signed keys.b3p.PortalSession verifies whichever format the org is using, so a package that has been upgraded works in both modes.Roll out in this order:
The field is marked as a temporary migration setting. When you check it:
A magic link is a portal URL with a magic link token attached as the sessionKey parameter:
https://<site>/b3p__Portal#<PortalName>?sessionKey=<token>&recordId=<optionalRecordId>
When the user opens the link, the frontend reads sessionKey from the URL at boot, removes it from the address bar and sends it to the redeemMagicLink action. The action returns a fresh session key, which the browser stores. Every subsequent Apex call sends the stored key.
A magic link token is never accepted as a session by itself. Any action other than redeemMagicLink rejects it, with or without One Time Magic Links.
Check One_Time_Magic_Links__c on the Portal custom setting to make each magic link work once.
| Step | What happens |
|---|---|
| Link minted | The 3B Get Magic Link action and the Portal Login As component on the Contact record mint a magic link token (type m). Keys from access codes, passkeys and login codes are session keys (type s). |
| First open | redeemMagicLink checks the link (expiry, Contact, Disabled_Portal_User__c), records a Magic Link Login Web Event, and returns a fresh session key. The browser stores the fresh key, not the link. |
| Second open | The link has already been used, so the user sees "This link has already been used and is no longer valid. Please request a new one." (label Portal_MagicLinkUsed). A session the browser already holds is kept. |
| Link used as a session directly | Rejected on every action. A magic link token is only accepted by redeemMagicLink, so calling loadUser or any other action with it does not bypass the check. |
Notes for administrators:
Magic Link Login Web Event re-enables its link.Portal_Magic_Link_Validity__c validity and the Session_Length_Minutes__c cap.Validity Minutes on the link for password reset style flows.The Portal Login As Lightning web component (loginAs) lets an internal user open a portal as a Contact, for support or testing. It runs as a Login As quick action on Contact (Contact.Login_As) or embedded on a Contact Lightning record page.
Publisher.getContactSession and shows it with a Copy button and a Log In As {Contact Name} button that opens it in a new tab.The link has the standard shape <site>/b3p__Portal#<Web Portal Name>?sessionKey=<token>, uses the Portal_Magic_Link_Validity__c validity and is marked as a magic link, so One Time Magic Links applies. A fresh link is minted on every selection change. With One Time Magic Links on, clicking the button consumes the link shown, so change a selection to mint a new one before copying it to the Contact.
Setup:
| Step | Where |
|---|---|
| Add the Login As action to the Contact page layout | Setup, Object Manager, Contact, Page Layouts, Mobile and Lightning Actions |
| Or drag Portal Login As onto a Contact record page | Lightning App Builder. The Portal Page property defaults to b3p__Portal |
Grant access to the Publisher Apex class and read access to Web_Portal__c |
Permission set |
Apex: Publisher.getData(recordId) returns { record: {Id, Name}, siteOptions: [{value,label}], portalOptions: [{value,label}] }. Publisher.getContactSession(contactId) returns the token:
{ "success": true, "responseObject": "<magic-link-token>" }
Use the invocable Apex action "3B Get Magic Link" (CreateSessionService.getSessionKey), category 3B Portals. It takes a Contact id and returns the token.
contactId (required). The Contact the link logs in.Validity Minutes (optional). How long the link stays valid, in minutes. Leave it blank to use the Portal_Magic_Link_Validity__c setting.sessionkey (the token), sessionkeyUrlSafe (the URL-encoded token for links; signed tokens are URL safe when Secure Session Keys is enabled), contactId, Expires At (the date and time the link stops working).A typical automation is a record triggered Flow that, for example on invitation, calls this action for the target Contact and emails them a link built as <siteUrl>/b3p__Portal#<Portal>?sessionKey=<sessionkeyUrlSafe>.
Set Validity Minutes per link when a single default does not fit. Common values:
| Use case | Validity Minutes |
|---|---|
| One time password reset style link | 15 |
| Same day action, for example confirm a shift | 1440 (one day) |
| Standard invitation | leave blank, uses the setting |
Validity Minutes must be greater than zero. Zero or a negative value fails the Flow interview with "Validity Minutes must be greater than zero" rather than quietly minting a dead link. Put the returned Expires At in the email so the recipient knows the deadline.
The frontend sends the key as sessionKey on any session gated action (for example loadUser). With Secure Session Keys on, a key is accepted only when all of these are true:
Disabled_Portal_User__c is not checked.Sessions_Revoked_At__c.On success the Contact is returned and a Login Web Event is logged at most once per day.
Other packages and custom Apex must not decode or check a session key themselves. They ask 3B Portals who the key belongs to. No secret is shared and no compile time dependency is needed:
Callable portal = (Callable) Type.forName('b3p', 'PortalSession').newInstance();
Map<String, Object> result = (Map<String, Object>) portal.call(
'verify', new Map<String, Object>{ 'sessionKey' => sessionKey });
Id contactId = (Boolean) result.get('valid') ? (Id) (String) result.get('contactId') : null;
Response:
{ "valid": true, "contactId": "003XXXXXXXXXXXXXXX", "expiresAt": 1790000000000 }
{ "valid": false, "contactId": null, "expiresAt": null }
For signed sessions, valid is true only when all five conditions above are met. While Secure Session Keys is off, legacy keys are checked under the compatibility rules described above. Always act as the returned contactId. Never trust a Contact id sent by the browser next to the key.
To give a Contact a way in from Apex, call the 3B Get Magic Link action (b3p.CreateSessionService.getSessionKey) for a link, or b3p.PortalLoginCode.issue(contactId, ttlSeconds) for a short lived one time code. See Terminal login codes. No other package can mint a session key.
Session_Length_Minutes__c on the Portal custom setting caps how long a single portal session may run. Leave it blank and a session lasts as long as Portal_Magic_Link_Validity__c (14 days by default). With Secure Session Keys off, a blank cap leaves expiry controlled by Expire_Session_Keys__c.
When it is set:
loadUser checks the incoming key. If it would outlive the cap, the server mints a replacement key that expires Session_Length_Minutes__c from now and returns it alongside the Contact.The cap only ever shortens a session. Reloading the page does not slide the window forward, so a 30 minute cap means 30 minutes from the first page load, not 30 minutes of inactivity.
With One Time Magic Links off, a magic link stays valid for its own validity window even after a capped session ends. Someone who opens a 14 day link, works for 30 minutes and is logged out can open the same link again the next day and get another 30 minute session. Shorten Validity Minutes on the link itself when the link should be single sitting.
| Setting | Value |
|---|---|
Portal_Magic_Link_Validity__c |
14 |
Session_Length_Minutes__c |
30 |
A Contact receives an invitation link on 1 March. They open it on 5 March at 09:00. The server issues a session key expiring 09:30. At 09:30 the browser logs them out. If One Time Magic Links is off, the invitation link still works until 15 March and each use grants a fresh 30 minutes. With it on, the first use consumes the link.
Portal_Magic_Link_Validity__c (days), or from the Validity Minutes input when a Flow supplies one.Expire_Session_Keys__c only applies while it is off.Session_Length_Minutes__c caps the length of each session independently of how long a magic link is valid.Sessions_Revoked_At__c on the Contact. Every signed session key issued to that Contact up to that point stops working on every device. Magic links that have not been opened follow their own validity, so use short link validity or One Time Magic Links where that matters.Sessions_Revoked_At__c on the Contact to the current date and time. To block them from coming back, check Disabled_Portal_User__c as well.b3p.PortalSession.revokeAllSessions();
Session_Length_Minutes__c in production so an unattended browser cannot hold an open session for the full link validity.One_Time_Magic_Links__c so a forwarded link cannot be reused.Disabled_Portal_User__c for immediate lockout.