Thanks to visit codestin.com
Credit goes to github.com

Skip to content
This repository was archived by the owner on May 3, 2024. It is now read-only.

Commit 86b54f6

Browse files
authored
Add wallet authenticator code examples (#106)
1 parent 14a727a commit 86b54f6

File tree

3 files changed

+38
-0
lines changed

3 files changed

+38
-0
lines changed

docs/docs/snippets.json

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -409,5 +409,38 @@
409409
],
410410
"properties": [],
411411
"reference": "https://docs.thirdweb.com/python/multiwrap"
412+
},
413+
"WalletAuthenticator": {
414+
"name": "WalletAuthenticator",
415+
"summary": "> This API is provided as a preview for developers and may change based on feedback that we receive. Do not use this API in a production environment. >",
416+
"example": "# We specify the domain of the application to authenticate to\ndomain = \"thirdweb.com\"\n\n# We can then generate a payload for the connected wallet to login\n# This can also be done on the client side with the thirdweb TypeScript SDK\npayload = sdk.auth.login(domain)\n\n# Then, on the server, we can securely verify the connected address that signed the payload\naddress = sdk.auth.verify(domain, payload)\n\n# And we can also generate an authentication token to send back to the original payload sender\ntoken = sdk.auth.generate_auth_token(domain, payload)\n\n# Finally, the token can be use dby the original payload sender to authenticate to the backend\n# And the server can use the following function to authenticate the token and verify the address\naddress = sdk.auth.authenticate(domain, token)",
417+
"methods": [
418+
{
419+
"name": "authenticate",
420+
"summary": "Server-side function that authenticates the provided JWT token. This function verifies that the provided authentication token is valid and returns the address of the authenticated wallet.",
421+
"example": "domain = \"thirdweb.com\"\npayload = sdk.auth.login(domain)\ntoken = sdk.auth.generate_auth_token(domain, payload)\n\n# Authenticate the token and get the address of the authenticating wallet\naddress = sdk.auth.authenticate(domain, token)",
422+
"reference": "https://docs.thirdweb.com/python/wallet-authenticator#authenticate"
423+
},
424+
{
425+
"name": "generate_auth_token",
426+
"summary": "Server-side function that generates a JWT token from the provided login request that the client-side wallet can use to authenticate to the server-side application.",
427+
"example": "domain = \"thirdweb.com\"\npayload = sdk.auth.login(domain)\n\n# Generate an authentication token for the logged in wallet\ntoken = sdk.auth.generate_auth_token(domain, payload)",
428+
"reference": "https://docs.thirdweb.com/python/wallet-authenticator#generate_auth_token"
429+
},
430+
{
431+
"name": "login",
432+
"summary": "Client-side function that allows the connected wallet to login to a server-side application. Generates a login payload that can be sent to the server-side for verification or authentication.",
433+
"example": "# Add the domain of the application that you want to log in to\ndomain = \"thirdweb.com\"\n\n# Generate a signed login payload for the connected wallet to authenticate with\npayload = sdk.auth.login(domain)",
434+
"reference": "https://docs.thirdweb.com/python/wallet-authenticator#login"
435+
},
436+
{
437+
"name": "verify",
438+
"summary": "Server-side function to securely verify the address of the logged in client-side wallet by validating the provided client-side login request.",
439+
"example": "domain = \"thirdweb.com\"\npayload = sdk.auth.login(domain)\n\n# Verify the login request\naddress = sdk.auth.verify(domain, payload)",
440+
"reference": "https://docs.thirdweb.com/python/wallet-authenticator#verify"
441+
}
442+
],
443+
"properties": [],
444+
"reference": "https://docs.thirdweb.com/python/wallet-authenticator"
412445
}
413446
}

scripts/generate_snippets.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@
2525
"ERC20": "erc20",
2626
"ERC721": "erc721",
2727
"ERC1155": "erc1155",
28+
"WalletAuthenticator": "wallet-authenticator",
2829
}
2930

3031

@@ -129,6 +130,9 @@ def generate():
129130
cls = getattr(thirdweb.contracts, contract)
130131
data[contract] = describe(cls)
131132

133+
cls = thirdweb.core.auth.WalletAuthenticator
134+
data["WalletAuthenticator"] = describe(cls)
135+
132136
with open("docs/docs/snippets.json", "w") as f:
133137
j = json.dumps(data, indent=4)
134138
f.write(j)

thirdweb/core/auth/__init__.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
from .wallet_authenticator import WalletAuthenticator

0 commit comments

Comments
 (0)