|
| 1 | +--- |
| 2 | +title: "Log in with JWT(BYOA)" |
| 3 | + |
| 4 | +sidebar_label: "Log in with JWT(BYOA)" |
| 5 | +description: "Web3Auth MPC Core Kit JS SDK - Login with JWT(BYOA) | Documentation - Web3Auth" |
| 6 | +--- |
| 7 | + |
| 8 | +import Tabs from "@theme/Tabs"; |
| 9 | +import TabItem from "@theme/TabItem"; |
| 10 | + |
| 11 | +To authenticate users using Regular Web Application(RWA) flow, you can use the `loginWithJWT` |
| 12 | +method. This methods takes the `JWTLoginParams` as a parameter, which is an object that contains the |
| 13 | +details of the verifier, and additional authentication parameters like idToken, subVerifier, etc. |
| 14 | + |
| 15 | +In JWT login flow, you'll have to manually get the idToken from the auth provider and pass it to the |
| 16 | +login function. |
| 17 | + |
| 18 | +## Parameters |
| 19 | + |
| 20 | +<Tabs |
| 21 | + defaultValue="table" |
| 22 | + values={[ |
| 23 | + { label: "Table", value: "table" }, |
| 24 | + { label: "Type", value: "type" }, |
| 25 | + ]} |
| 26 | +> |
| 27 | + |
| 28 | +<TabItem value="table"> |
| 29 | + |
| 30 | +| Parameter | Description | |
| 31 | +| ------------------------ | ----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | |
| 32 | +| `verifier` | Name of the verifier created on Web3Auth Dashboard. In the case of Aggregate Verifier, the name of the top-level aggregate verifier. | |
| 33 | +| `verifierId` | Unique Identifier for the User. The verifier identifier field is set for the verifier/sub verifier. E.g. "sub" field in your JWT ID Token. | |
| 34 | +| `idToken` | The idToken received from the Auth Provider. | |
| 35 | +| `subVerifier?` | Name of the sub verifier in case of aggregate verifier setup. This field is mandatory in the case of an aggregate verifier. | |
| 36 | +| `extraVerifierParams?` | Extra verifier params in case of a WebAuthn verifier type. | |
| 37 | +| `additionalParams?` | Any additional parameter (key-value pair) you'd like to pass to the login function. | |
| 38 | +| `importTssKey?` | Key to import key into TSS during first time login. For secp256k1 curve, you need to pass the private key, and for ed25519 curve you need to pass the seed. The ed25519 seed is hashed to generate 64 bytes, where first 32 bytes are used to generate the public key, and last 32 bytes are used as private key. | |
| 39 | +| `prefetchTssPublicKeys?` | Number of TSS public keys to prefetch. | |
| 40 | + |
| 41 | +</TabItem> |
| 42 | +<TabItem value="type"> |
| 43 | + |
| 44 | +```tsx |
| 45 | +interface JWTLoginParams { |
| 46 | + /** |
| 47 | + * Name of the verifier created on Web3Auth Dashboard. In case of Aggregate Verifier, the name of the top level aggregate verifier. |
| 48 | + */ |
| 49 | + verifier: string; |
| 50 | + /** |
| 51 | + * Unique Identifier for the User. The verifier identifier field set for the verifier/ sub verifier. E.g. "sub" field in your on jwt id token. |
| 52 | + */ |
| 53 | + verifierId: string; |
| 54 | + /** |
| 55 | + * The idToken received from the Auth Provider. |
| 56 | + */ |
| 57 | + idToken: string; |
| 58 | + /** |
| 59 | + * Name of the sub verifier in case of aggregate verifier setup. This field should only be provided in case of an aggregate verifier. |
| 60 | + */ |
| 61 | + subVerifier?: string; |
| 62 | + /** |
| 63 | + * Extra verifier params in case of a WebAuthn verifier type. |
| 64 | + */ |
| 65 | + extraVerifierParams?: PasskeyExtraParams; |
| 66 | + /** |
| 67 | + * Any additional parameter (key value pair) you'd like to pass to the login function. |
| 68 | + */ |
| 69 | + additionalParams?: ExtraParams; |
| 70 | + /** |
| 71 | + * Key to import key into Tss during first time login. |
| 72 | + */ |
| 73 | + importTssKey?: string; |
| 74 | + /** |
| 75 | + * Number of TSS public keys to prefetch. For the best performance, set it to |
| 76 | + * the number of factors you want to create. Set it to 0 for an existing user. |
| 77 | + * Default is 1, maximum is 3. |
| 78 | + */ |
| 79 | + prefetchTssPublicKeys?: number; |
| 80 | +} |
| 81 | + |
| 82 | +export interface ExtraParams { |
| 83 | + [key: string]: unknown; |
| 84 | +} |
| 85 | + |
| 86 | +export type WebAuthnExtraParams = { |
| 87 | + signature?: string; |
| 88 | + clientDataJSON?: string; |
| 89 | + authenticatorData?: string; |
| 90 | + publicKey?: string; |
| 91 | + challenge?: string; |
| 92 | + rpOrigin?: string; |
| 93 | + credId?: string; |
| 94 | + transports?: AuthenticatorTransport[]; |
| 95 | +}; |
| 96 | + |
| 97 | +type AuthenticatorTransport = "ble" | "hybrid" | "internal" | "nfc" | "usb"; |
| 98 | +``` |
| 99 | + |
| 100 | +</TabItem> |
| 101 | + |
| 102 | +</Tabs> |
| 103 | + |
| 104 | +## Usage |
| 105 | + |
| 106 | +### Single Verifier |
| 107 | + |
| 108 | +To login with a single verifier, you will require to create a custom verifier in the Web3Auth |
| 109 | +dashboard. If you haven't already created one, |
| 110 | +[learn how to create a verifier](/docs/auth-provider-setup/byo-jwt-provider/#set-up-custom-jwt-verifier). |
| 111 | + |
| 112 | +```tsx |
| 113 | +import { JWTLoginParams } from "@web3auth/mpc-core-kit"; |
| 114 | + |
| 115 | +const jwtLoginParams: JWTLoginParams = { |
| 116 | + verifier: "YOUR_VERIFIER_NAME", |
| 117 | + verifierId: "USER'S_VERIFIER_ID", |
| 118 | + idToken: "USER'S_ID_TOKEN", |
| 119 | +}; |
| 120 | + |
| 121 | +await coreKitInstance.loginWithJWT(jwtLoginParams); |
| 122 | +``` |
| 123 | + |
| 124 | +### Aggregate Verifier |
| 125 | + |
| 126 | +To login with an aggregate verifier, you will require to create an aggregate verifier in the |
| 127 | +Web3Auth dashboard. If you haven't already created one, |
| 128 | +[learn how to create an aggregate verifier](/docs/auth-provider-setup/aggregate-verifier#set-up-an-aggregate-verifier). |
| 129 | + |
| 130 | +```tsx |
| 131 | +import { JWTLoginParams } from "@web3auth/mpc-core-kit"; |
| 132 | + |
| 133 | +const jwtLoginParams = { |
| 134 | + verifier: "YOUR_AGGREGATE_VERIFIER_NAME" |
| 135 | + subVerifier: "YOUR_SUB_VERIFIER_NAME", |
| 136 | + verifierId: "USER'S_VERIFIER_ID", |
| 137 | + idToken: "USER'S_ID_TOKEN", |
| 138 | +} as JWTLoginParams; |
| 139 | + |
| 140 | +await coreKitInstance.loginWithJWT(jwtLoginParams); |
| 141 | +``` |
| 142 | + |
| 143 | +## Importing an existing account. |
| 144 | + |
| 145 | +During the first-time login with `Web3AuthMPCCoreKit`, you can import an existing account using the |
| 146 | +`importTssKey` parameter. To import a secp256k1 chain account, be sure to provide the private key in |
| 147 | +hex format. For an ed25519 chain account, you need to pass the seed. |
| 148 | + |
| 149 | +By default, the ed25519 key is formatted in base58 and is 64 bytes long. This consists of the first |
| 150 | +32 bytes as the seed (also known as the private key) and the last 32 bytes as the public key. Ensure |
| 151 | +that the first 32 bytes are provided in hexadecimal format when using the ed25519 seed. |
| 152 | + |
| 153 | +```tsx |
| 154 | +import { JWTLoginParams } from "@web3auth/mpc-core-kit"; |
| 155 | + |
| 156 | +const jwtLoginParams = { |
| 157 | + verifier: "YOUR_VERIFIER_NAME", |
| 158 | + verifierId: "USER'S_VERIFIER_ID", |
| 159 | + idToken: "USER'S_ID_TOKEN", |
| 160 | + // focus-next-line |
| 161 | + importTssKey: "SECP256K1_PRIVATE_KEY_OR_ED25519_SEED", |
| 162 | +} as JWTLoginParams; |
| 163 | + |
| 164 | +await coreKitInstance.loginWithJWT(jwtLoginParams); |
| 165 | +``` |
0 commit comments