Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions .changeset/tough-ads-grow.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'@asgardeo/react': patch
---

Handle code exchange for V2
28 changes: 21 additions & 7 deletions packages/react/src/contexts/Asgardeo/AsgardeoProvider.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -156,14 +156,28 @@ const AsgardeoProvider: FC<PropsWithChildren<AsgardeoProviderProps>> = ({

const isV2Platform = config.platform === Platform.AsgardeoV2;

if (hasAuthParamsResult && !isV2Platform) {
if (hasAuthParamsResult) {
try {
await signIn(
{callOnlyOnRedirect: true},
// authParams?.authorizationCode,
// authParams?.sessionState,
// authParams?.state,
);
if (isV2Platform) {
// For V2 platform, check if this is an embedded flow or traditional OAuth
const urlParams = currentUrl.searchParams;
const code = urlParams.get('code');
const flowIdFromUrl = urlParams.get('flowId');
const storedFlowId = sessionStorage.getItem('asgardeo_flow_id');

// If there's a code and no flowId, exchange OAuth code for tokens
if (code && !flowIdFromUrl && !storedFlowId) {
await signIn();
}
} else {
// If non-V2 platform, use traditional OAuth callback handling
await signIn(
{callOnlyOnRedirect: true},
// authParams?.authorizationCode,
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Shall we remove the commented code if not needed?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not handling it in this PR here since it was existing

// authParams?.sessionState,
// authParams?.state,
);
}
// setError(null);
} catch (error) {
if (error && Object.prototype.hasOwnProperty.call(error, 'code')) {
Expand Down
Loading