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:
| Stage | Behavior |
|---|---|
| Login | Checks the configured extension ID, loads issuer discovery, and generates a fresh state, an S256 verifier, and its challenge. |
| Callback | Checks the origin, the path, the state, and any returned issuer. Rejects duplicate or conflicting response parameters and consumes the transaction. |
| Token exchange | Sends the original callback and verifier. Reads expiry from expires_in. Saves a refresh token when the provider issues one. |
| Account check | Sends the access token to /api/v1/me. Returns only the handle, the connection status, and the granted scopes to the popup. |
| Renewal | Runs one renewal at a time and keeps any replacement refresh token. A temporary failure keeps the refresh token. invalid_grant clears the connection. |
| Log out | Clears tokens and pending state. Late login, refresh, and account responses cannot restore 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.
| Check | Expected result |
|---|---|
| Close and reopen the popup | Check account reads the connected account while the session stays valid. |
| Stop the worker, then reopen the popup | Stored tokens are available. Account checks and renewal work without tokens from the page. |
| Reload or update the extension | With this storage choice, the user must log in again. |
| Quit and reopen the browser | With this storage choice, the user must log in again. |
| Let the access token approach expiry | An account check uses renewal when a refresh token is available. Without one, it requests another connection. |
| Close the authorization window | The popup says that login was not completed. It does not claim that the provider denied a permission. |
| Log out while an account check or renewal is pending | No late result restores tokens or the logged-in display. |
| Log out, then log in again | Earlier requests cannot overwrite the later connection. |
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:
| Result | Cause and fix |
|---|---|
| Configure client | config.js lacks the approved Login client ID, or the extension ID does not match the installed extension. Correct config.js. |
| Login not completed | The window closed or authorization failed. Start a fresh attempt. This result alone does not show that the user denied consent. |
| Invalid callback | The registered callback differs from getRedirectURL("callback"), or the response belongs to another login attempt. Register the exact callback. |
| Token error | Check client approval, the exact callback, and the PKCE verifier. Read the error code of the endpoint. Keep tokens and token responses out of logs. |
| Network error | Check the network connection and the extension permissions for the issuer and API hosts. Retry without deleting a valid refresh token. |
| Reconnect required | The session expired, has no usable refresh token, or session storage was cleared. Log in again. |
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.
