Add login to a Chromium extension
Add RemiliaNET login to a Chromium extension with the downloadable example, and read the connected account.
Chromium's identity API opens the login window for a public Login client. The background worker stores tokens, and the popup receives only the handle, the connection status, and the granted scopes.
The example has no client secret, no content scripts, and no access to website
cookies. It reads identity from the /me response and discards ID tokens
without decoding their claims. An extension that uses ID token claims validates
them with a maintained OpenID Connect (OIDC) library.
Prerequisites
- Chrome or another Chromium browser.
- A RemiliaNET account that can register a Login client in the developer portal.
The callback has the form https://<extension-id>.chromiumapp.org/callback.
During development, keep the extension folder and ID unchanged. A public
manifest key can fix the development ID. A release uses your signed distribution
identity, and the private signing key stays out of the archive. If the
development ID and the release ID differ, register a separate client for each
callback.
Steps
- Download the extension example.
- Extract the archive to a folder.
- Open
chrome://extensionsin Chrome. - Enable Developer mode.
- Select Load unpacked for the extracted folder.
- Copy the extension ID into
extensionIdinconfig.js. - Open the service worker inspector of the extension.
- Evaluate
chrome.identity.getRedirectURL("callback"). - Register the returned URL on a Login client in the developer portal.
- Wait for client approval.
- Copy the client ID into
clientIdinconfig.js. - Reload the extension.
- Select Log in with RemiliaNET in the popup.
- Select Check account to read the connected account.
Result
The popup shows the handle of the connected account. Log out removes the stored tokens and the account display of the extension.
The example makes no provider requests until you configure the client ID and the
extension ID. It requests openid and calls only the profile endpoint of the
logged-in user. Other features need their API scopes.
Behavior of the example
The example implements each stage of the connection:
The archive includes the official login control. The
source files are manifest.json, config.js, background.js, popup.html,
popup.js, and popup.css.
The background worker accepts three actions from its own popup. An extension that adds content scripts or other views checks the caller of each message. It returns only the data that the caller needs and keeps tokens out of messages.
Connection lifetime
The example stores tokens in chrome.storage.session, which only trusted
contexts can read. Tokens survive a closed popup and a recreated worker during a
browser session. A reload, an update, or a disable of the extension clears that
storage. A browser restart clears it too, and the user must log in again.
After an interrupted authorization window, the user might need a fresh login attempt. Storage duration does not set token expiry. The provider can ask for consent when the user connects again. For more information about these limits, see the Chromium storage reference.
Browser checks
Each check uses your registered test client and account and a fresh /me
request. A cached name is not evidence of an active connection. Tokens and raw
private responses stay out of screenshots and logs.
The behavior can differ between Chromium versions. The identity API describes how the browser handles the authorization window. Log out in this example performs no remote revocation and no provider logout.
Troubleshooting
The popup shows one of these results when a connection fails:
Connection status and issued permissions are separate states. For missing scopes, see App permissions.
Next steps
- For persistent storage or remote revocation, see Token and session security.
