-
Notifications
You must be signed in to change notification settings - Fork 428
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(thirdweb): adds redirect oauth (#3822)
### TL;DR Added support for OAuth redirects in the In-App wallet authentication flow. ### What changed? 1. Introduced `auth.mode` with options ` --- <!-- start pr-codex --> --- ## PR-Codex overview This PR introduces the ability to open OAuth windows as a redirect, beneficial for embedded applications like Telegram web apps. ### Detailed summary - Added `mode: "redirect"` option for OAuth windows - Implemented functions for OAuth redirection - Updated authentication options for in-app wallets > The following files were skipped due to too many changes: `packages/thirdweb/src/react/core/hooks/wallets/useAutoConnect.ts`, `packages/thirdweb/src/wallets/in-app/web/lib/web-connector.ts` > ✨ Ask PR-Codex anything about this PR by commenting with `/codex {your question}` <!-- end pr-codex -->
- Loading branch information
1 parent
bff7a0a
commit 3848327
Showing
15 changed files
with
198 additions
and
17 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
--- | ||
"thirdweb": minor | ||
--- | ||
|
||
Adds the ability to open OAuth windows as a redirect. This is useful for embedded applications such as telegram web apps. | ||
|
||
Be sure to include your domain in the allowlisted domains for your client ID. | ||
|
||
```ts | ||
import { inAppWallet } from "thirdweb/wallets"; | ||
const wallet = inAppWallet({ | ||
auth: { | ||
mode: "redirect" | ||
} | ||
}); | ||
``` |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
36 changes: 36 additions & 0 deletions
36
packages/thirdweb/src/wallets/in-app/web/lib/get-url-token.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
import type { AuthOption } from "../../../../wallets/types.js"; | ||
import type { WalletId } from "../../../wallet-types.js"; | ||
import type { AuthStoredTokenWithCookieReturnType } from "../../core/authentication/type.js"; | ||
|
||
/** | ||
* Checks for an auth token and associated metadata in the current URL | ||
*/ | ||
export function getUrlToken(): { | ||
walletId?: WalletId; | ||
authResult?: AuthStoredTokenWithCookieReturnType; | ||
authProvider?: AuthOption; | ||
} { | ||
if (!window) { | ||
throw new Error("Attempted to fetch a URL token on the server"); | ||
} | ||
|
||
const queryString = window.location.search; | ||
const params = new URLSearchParams(queryString); | ||
const authResultString = params.get("authResult"); | ||
const walletId = params.get("walletId") as WalletId | undefined; | ||
const authProvider = params.get("authProvider") as AuthOption | undefined; | ||
|
||
if (authResultString && walletId) { | ||
const authResult = JSON.parse(authResultString); | ||
params.delete("authResult"); | ||
params.delete("walletId"); | ||
params.delete("authProvider"); | ||
window.history.pushState( | ||
{}, | ||
"", | ||
`${window.location.pathname}?${params.toString()}`, | ||
); | ||
return { walletId, authResult, authProvider }; | ||
} | ||
return {}; | ||
} |
Oops, something went wrong.