blazor-authentication

Implement Sign-In with Ethereum authentication in Blazor using SIWE, JWT tokens, and AuthorizeView.

2.3k|744|Updated Nov 23, 2015
One-click install
npx skills add https://github.com/Nethereum/Nethereum --skill blazor-authentication
Or copy as Structured Prompt for Agent
Please help me install this Agent Skill.
Skill: blazor-authentication
Source: https://github.com/Nethereum/Nethereum/tree/main/plugins/nethereum-skills/skills/blazor-authentication
Command: npx skills add https://github.com/Nethereum/Nethereum --skill blazor-authentication

SYSTEM DOCUMENTATION & REQUIREMENTS

💡 This Skill requires Nethereum.Siwe, Nethereum.Blazor.

What problem does it solve?

Adding wallet-based login to a Blazor application requires implementing the SIWE (EIP-4361) message flow, signature verification, session or JWT management, and Blazor authorization integration, which is complex to wire up correctly from scratch.

Core Features & Use Cases

  • SIWE Authentication Flow: Generate SIWE messages with nonces, prompt wallet signatures, verify signatures, and issue JWTs or server sessions for both Blazor Server and Blazor WASM hosting models.
  • Blazor Authorization Integration: Use EthereumConnected and SiweAuthenticated roles with AuthorizeView and custom AuthenticationStateProvider implementations to gate UI and components.
  • Advanced Wallet Support: Verify smart contract wallet signatures via ERC-1271 and ERC-6492, and gate access by NFT ownership using ERC721BalanceEthereumUserService.
  • Use Case: A developer building a Blazor WASM dApp can stand up a REST API that issues SIWE messages, validates signed messages against stored nonces, and returns JWTs so users log in with MetaMask instead of passwords.

Quick Start

Implement Sign-In with Ethereum authentication in my Blazor app using Nethereum.Siwe with JWT tokens and an AuthorizeView-protected page.

Frequently Asked Questions about blazor-authentication

High-intent search queries and answers about installing and using this skill.

FAQPage Schema
How do I implement Sign-In with Ethereum in Blazor?

Use Nethereum.Siwe and Nethereum.Blazor to build a SIWE message with a nonce, have the wallet sign it, verify the signature server-side, then issue a JWT or session. Register SiweAuthenticationServerStateProvider for Blazor Server or call a REST API from Blazor WASM.

How to add JWT authentication with Ethereum wallets in Blazor WASM?

Create REST endpoints that generate a SIWE message and authenticate the signed message, returning a JWT via SiweJwtAuthorisationService. The WASM client signs the message through IEthereumHostProvider and stores the token with IAccessTokenService.

Does Nethereum SIWE support smart contract wallets like Safe?

Yes. Pass a Web3 instance to SiweMessageService and IsMessageSignatureValid automatically falls back to ERC-1271 on-chain verification. It also supports ERC-6492 for counterfactual smart wallets that are not yet deployed.

Can I restrict Blazor login to users holding a specific NFT?

Yes. Configure SiweMessageService with ERC721BalanceEthereumUserService pointing at your NFT contract address. IsUserAddressRegistered then checks the user's ERC-721 balance before allowing authentication to proceed.

Why does SIWE authentication fail with a nonce mismatch error?

Nonce mismatch occurs when the submitted SIWE message does not match the message stored in session by BuildMessageToSign. Ensure the client signs the exact message string returned by the server and that session storage persists between requests.