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

Invalid success param when using OAuth2 login #34

Open
schoolofai opened this issue Oct 10, 2024 · 2 comments
Open

Invalid success param when using OAuth2 login #34

schoolofai opened this issue Oct 10, 2024 · 2 comments
Assignees

Comments

@schoolofai
Copy link

schoolofai commented Oct 10, 2024

hi i am having issues with using google oauth for login - I am using react native sdk - it all works when on expo go , but when i installed it to testfight it stops working - and when trying to login with google - in get invalid sucess param should be one of - localhost .... etc . here is my sign in code -

    let redirectUri = makeRedirectUri({ preferLocalhost: true });
    console.log("Redirect URI:", redirectUri);

    const url = await account.createOAuth2Token(
      "google",
      redirectUri,
      redirectUri,
      [
        "profile",
        "email",
        "https://www.googleapis.com/auth/youtube",
        "https://www.googleapis.com/auth/youtube.force-ssl",
        "https://www.googleapis.com/auth/youtube.upload",
        "https://www.googleapis.com/auth/youtubepartner",
      ]
    );
    console.log("URL:", url);
    if (!url) {
      throw new Error("Failed to create OAuth2 session");
    }

    const result = await openAuthSessionAsync(url.href, redirectUri);
    console.log("Auth session result:", result);

    if (result.type === "success") {
      if ("url" in result) {
        const resultUrl = new URL(result.url);
        const secret = resultUrl.searchParams.get("secret");
        const userId = resultUrl.searchParams.get("userId");
        if (!secret || !userId) return;
        await account.createSession(userId, secret);
        const user = await account.get().catch((e) => {
          console.warn(e);
          return null;
        });
        console.log("user:", user);

see the screen shot for google cloud credentials
ImageImage

@eldadfux eldadfux transferred this issue from appwrite/appwrite Oct 24, 2024
@stnguyen90 stnguyen90 transferred this issue from appwrite/sdk-generator Oct 28, 2024
@stnguyen90 stnguyen90 added the question Further information is requested label Oct 28, 2024
@stnguyen90
Copy link
Contributor

@schoolofai, thanks for creating this issue! 🙏🏼 Could you please share exactly what the redirectUri is when running via TestFlight? It's likely the hostname in the URL hasn't been registered in your Appwrite project yet.

@stnguyen90 stnguyen90 self-assigned this Oct 28, 2024
@stnguyen90 stnguyen90 changed the title React Native SDK - Cant Auth when on testflight Cant Auth when on testflight Oct 28, 2024
@stnguyen90 stnguyen90 changed the title Cant Auth when on testflight Cant OAuth2 when on testflight Oct 28, 2024
@stnguyen90 stnguyen90 removed the question Further information is requested label Jan 18, 2025
@stnguyen90
Copy link
Contributor

So, at the moment, Expo will create deep links like:

  • Development and production builds: <scheme>://path - uses the optional scheme property if provided, and otherwise uses the first scheme defined by your app config
  • Web (dev): https://localhost:19006/path
  • Web (prod): https://myapp.com/path
  • Expo Go (dev): exp://128.0.0.1:8081/--/path

Appwrite will try to validate the host part of the URL against the allowed web platforms to protect against open redirect attacks so you'll get a 400 error like:

Invalid success param: URL host must be one of: localhost, cloud.appwrite.io, appwrite.io

It's impossible to change RN to include a hostname or you may run into a path not found error when redirect back into the RN app.

@stnguyen90 stnguyen90 changed the title Cant OAuth2 when on testflight Invalid success param when using OAuth2 login Jan 18, 2025
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

2 participants