Skip to content

feat: add requestAttributes for signed user attributes#85

Merged
sea-snake merged 8 commits intomainfrom
sea-snake/request-attributes
Apr 17, 2026
Merged

feat: add requestAttributes for signed user attributes#85
sea-snake merged 8 commits intomainfrom
sea-snake/request-attributes

Conversation

@sea-snake
Copy link
Copy Markdown
Contributor

@sea-snake sea-snake commented Apr 8, 2026

Adds a requestAttributes method to AuthClient that requests signed user attributes from the identity provider via the signer's JSON-RPC interface. Attributes can be requested in parallel with sign-in.

The method requires a canister-issued nonce to prevent replay attacks and bind attributes to a specific backend action. The signed attribute bundle also includes implicit:origin and implicit:issued_at_timestamp_ns for the backend canister to verify.

const authClient = new AuthClient();

const nonce: Uint8Array = await backend.registerBegin();
const signInPromise = authClient.signIn();
const attributesPromise = authClient.requestAttributes({ keys: ['email'], nonce });

await signInPromise;
const { data, signature } = await attributesPromise;

The method sends an ii-icrc3-attributes JSON-RPC request with the requested attribute keys and the provided nonce, and returns the base64-decoded data and signature as Uint8Array. Throws on error responses or invalid results.

Breaking changes

  • AuthClient.login() is renamed to AuthClient.signIn().
  • AuthClientLoginOptions is renamed to AuthClientSignInOptions.

Prev: #84

@sea-snake sea-snake requested a review from a team as a code owner April 8, 2026 12:06
@sea-snake sea-snake force-pushed the sea-snake/request-attributes branch 3 times, most recently from 899b643 to 15bf417 Compare April 8, 2026 12:14
@sea-snake sea-snake force-pushed the sea-snake/request-attributes branch 10 times, most recently from 3247078 to 9fcfdf9 Compare April 8, 2026 12:39
@sea-snake sea-snake requested review from aterga and Copilot April 8, 2026 12:40
@sea-snake sea-snake force-pushed the sea-snake/request-attributes branch from 9fcfdf9 to e1ebd89 Compare April 8, 2026 12:41
Copy link
Copy Markdown

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This pull request adds a requestAttributes method to AuthClient that enables requesting signed user attributes from the identity provider via a JSON-RPC interface. The method can be called during login or separately, allowing attributes like email and name to be requested and verified with cryptographic signatures.

Changes:

  • Added requestAttributes method to AuthClient class for requesting signed user attributes with optional custom nonce
  • Added SignedAttributes interface to represent the signed attribute response (data and signature as Uint8Array)
  • Exported OPENID_PROVIDER_URLS constant to support documentation examples
  • Implemented base64 encoding/decoding helper functions with fallback support for native Uint8Array methods
  • Added comprehensive tests covering normal flow, custom nonce, random nonce generation, error handling, and validation
  • Updated README and quick-start documentation with usage examples

Reviewed changes

Copilot reviewed 4 out of 4 changed files in this pull request and generated 2 comments.

File Description
src/client/auth-client.ts Added requestAttributes method, SignedAttributes interface, and base64 helper functions; exported OPENID_PROVIDER_URLS
tests/client/auth-client.test.ts Added mocking for sendRequest method and comprehensive tests for requestAttributes functionality
README.md Added documentation section with usage examples for requesting user attributes
docs/src/content/docs/quick-start.md Updated quick-start guide to show parallel login and attribute request pattern

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment thread src/client/auth-client.ts
Comment thread src/client/auth-client.ts Outdated
@sea-snake sea-snake force-pushed the sea-snake/request-attributes branch 10 times, most recently from f76aa6f to f6ea3fe Compare April 8, 2026 14:21
@sea-snake sea-snake force-pushed the sea-snake/request-attributes branch from c0bf998 to d92b50e Compare April 15, 2026 15:33
Comment thread docs/src/content/docs/quick-start.md Outdated
Comment thread docs/src/content/docs/quick-start.md Outdated
Comment thread README.md Outdated
Comment thread README.md Outdated
Comment thread README.md Outdated
@sea-snake sea-snake force-pushed the sea-snake/request-attributes branch 3 times, most recently from 13d4689 to dbc54d2 Compare April 16, 2026 05:45
sea-snake added a commit that referenced this pull request Apr 16, 2026
Reorganizes `auth-client.ts` for clarity:

- Class moved before free functions (public API is the first thing you
see)
- Within the class: constructor → public methods → private methods
- Free functions ordered: key helpers → chain helpers → storage helpers
→ migration
- Removed unused `#key` field
- Renamed `#createOptions` to `#options`
- Simplified `#hydrate()` — delegates key restoration and migration to
`restoreKey()` which calls `migrateFromLocalStorage()` as a fallback
- Cleaned up JSDoc throughout
- Removed `localStorage` try/catch wrappers (assumed always available)
- Disabled `pnpm audit` CI workflow due to
[pnpm/pnpm#11265](pnpm/pnpm#11265)

---
Prev: #83 | Next: #85

---------

Co-authored-by: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
Base automatically changed from sea-snake/cleanup to main April 16, 2026 05:46
sea-snake and others added 2 commits April 16, 2026 07:49
- Simplify internetIdentityCanisterId in quick-start (remove unnecessary branching)
- Rename "user attributes" to "identity attributes" in README and JSDoc

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
@sea-snake sea-snake force-pushed the sea-snake/request-attributes branch from dbc54d2 to 21622bc Compare April 16, 2026 05:58
@sea-snake sea-snake requested a review from aterga April 16, 2026 06:01
sea-snake and others added 4 commits April 17, 2026 13:37
The nonce parameter is now mandatory to enforce that it originates from
the RP canister, preventing replay attacks from compromised frontends.
README examples updated to use the nonce-based flow as the default
pattern, with documentation of all implicit verification fields.

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
@sea-snake sea-snake merged commit 829418d into main Apr 17, 2026
10 checks passed
@sea-snake sea-snake deleted the sea-snake/request-attributes branch April 17, 2026 16:16
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants