Skip to content

Commit

Permalink
Merge pull request #723 from magiclabs/PDEEXP-530-wallet-connect-logi…
Browse files Browse the repository at this point in the history
…n-with-redirect

add shouldReturnURI to configuration
  • Loading branch information
Ethella authored Dec 13, 2024
2 parents a4f320d + ab0dfc7 commit 9c1662c
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 8 deletions.
21 changes: 13 additions & 8 deletions packages/@magic-ext/oauth2/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ export class OAuthExtension extends Extension.Internal<'oauth2'> {
}

public loginWithRedirect(configuration: OAuthRedirectConfiguration) {
return this.utils.createPromiEvent<void>(async (resolve, reject) => {
return this.utils.createPromiEvent<null | string>(async (resolve, reject) => {
const parseRedirectResult = this.utils.createJsonRpcRequestPayload(OAuthPayloadMethods.Start, [
{
...configuration,
Expand All @@ -58,18 +58,23 @@ export class OAuthExtension extends Extension.Internal<'oauth2'> {
}

if (successResult?.oauthAuthoriationURI) {
window.location.href = successResult.useMagicServerCallback
const redirectURI = successResult.useMagicServerCallback
? // @ts-ignore - this.sdk.endpoint is marked protected but we need to access it.
new URL(successResult.oauthAuthoriationURI, this.sdk.endpoint).href
: successResult.oauthAuthoriationURI;
}

resolve();
if (successResult?.shouldReturnURI) {
resolve(redirectURI);
} else {
window.location.href = redirectURI;
}
}
resolve(null);
});
}

public getRedirectResult(lifespan?: number) {
const queryString = window.location.search;
public getRedirectResult(lifespan?: number, optionalQueryString?: string) {
const queryString = optionalQueryString || window.location.search;

// Remove the query from the redirect callback as a precaution to prevent
// malicious parties from parsing it before we have a chance to use it.
Expand Down Expand Up @@ -113,8 +118,8 @@ export class OAuthExtension extends Extension.Internal<'oauth2'> {
console.log('Error while verifying telegram data', verificationError);
}
}
} catch (seamlessLoginError) {
console.log('Error while loading telegram-web-app script', seamlessLoginError);
} catch (seamlessLoginError) {
console.log('Error while loading telegram-web-app script', seamlessLoginError);
}
}
}
Expand Down
1 change: 1 addition & 0 deletions packages/@magic-ext/oauth2/src/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,7 @@ export type OpenIDConnectUserInfo = OpenIDConnectProfile &
export interface OAuthRedirectStartResult {
oauthAuthoriationURI?: string;
useMagicServerCallback?: boolean;
shouldReturnURI?: boolean;
}

export interface OAuthRedirectResult {
Expand Down

0 comments on commit 9c1662c

Please sign in to comment.