Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

SSO Token does not working in the second time using react-native and expo #173

Open
leandroSalesCotrim opened this issue Nov 8, 2024 · 1 comment

Comments

@leandroSalesCotrim
Copy link

I'm having problems when trying to execute the request that gets the code value that is used to obtain the token to connect to the PlayStation API. I've tried everything and I can't understand what it could be. Where I tested the correct value of the SSO token, it reaches the function, but when it tries to communicate with Sony's servers to get the value, it only works on the first attempt in the app on my cell phone. From the second attempt onwards, the request stops working and returns the status code 200, the expected code was 302. I can only make the request return 302 again by clearing the app cache in my cell phone's settings. So I imagine that somehow React Native or Expo may be storing some value or section that is interfering with the requests.

async exchangeNpssoForCode(npssoToken: string): Promise {
console.log("Token NPSSO atual:", npssoToken);

    const queryString = new URLSearchParams({
        access_type: "offline",
        client_id: "09515159-7237-4370-9b40-3806e67c0891",
        redirect_uri: "com.scee.psxandroid.scecompcall://redirect",
        response_type: "code",
        scope: "psn:mobile.v2.core psn:clientapp"
    }).toString();

    const requestUrl = `https://ca.account.sony.com/api/authz/v3/oauth/authorize?${queryString}`;

    const response = await fetch(requestUrl, {
        headers: {
            'Cookie': `npsso=${npssoToken}`
        },
        redirect: "manual"  
    });

    const responseHeaders = response.headers;

    if (!responseHeaders.has("location") || !responseHeaders.get("location")?.includes("?code=")) {
        throw new Error(`
            There was a problem retrieving your PSN access code. Is your NPSSO code valid?
            To get a new NPSSO code, visit https://ca.account.sony.com/api/v1/ssocookie.
        `);
    }

    // Captura o código de autorização da URL de redirecionamento
    const redirectLocation = responseHeaders.get("location") as string;
    const redirectParams = new URLSearchParams(redirectLocation.split("redirect/")[1]);
    return redirectParams.get("code") as string;
}

I've also tested the exact same code being executed on my PC in isolation in TypeScript and JavaScript, and both methods worked using Axio and Fetch. However, the problem only occurs in my React Native app. I haven't found anything about it on the internet and I can't find another solution.

I tried to debug the code, I already know that the SSO value is correct and valid, if the SSO is invalid then obviously it will return an error and status code 200, but something happens only from the second request onwards that even receiving the correct value, the request always returns 200 and not 302
I have also tried to leave a fixed value for the valid token and the result is the same, on the first attempt it works, on the second attempt the error starts

@leandroSalesCotrim
Copy link
Author

if someone can help i'm here to give more information about my problem

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant