Skip to content

Invalid success param when using OAuth2 login #34

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

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

Invalid success param when using OAuth2 login #34

schoolofai opened this issue Oct 10, 2024 · 11 comments
Assignees
Labels
bug Something isn't working

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

stnguyen90 commented Jan 18, 2025

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.

We'll have to discuss internally about how to handle react native.

@stnguyen90 stnguyen90 changed the title Cant OAuth2 when on testflight Invalid success param when using OAuth2 login Jan 18, 2025
@stnguyen90
Copy link
Contributor

appwrite/appwrite#9262 was merged but then reverted due to issues during QA. We'll need to fix the issues with another PR.

@Nizam-shan
Copy link

same issue here general_argument_invalid working fine in ios simulation and expo qr code run issue in android emulator
export async function login() {
try {
// need to generate redirect uri for oauth response (once go to google it has to move back to application again (can use expo module foe handling deep links))
const redirectUri = Linking.createURL("/");

// padding redirect url and auth provider
const response = await account.createOAuth2Token(
  OAuthProvider.Google,
  redirectUri
);
if (!response) throw new Error("Failed to Login");

const browserResult = await openAuthSessionAsync(
  response.toString(),
  redirectUri
);
if (browserResult.type !== "success") throw new Error("Failed to login");
const url = new URL(browserResult.url);

@mnkyjs
Copy link

mnkyjs commented Mar 28, 2025

I have the same problem, here is my current implementation

import { getQueryParams } from "expo-auth-session/build/QueryParams";
import { openAuthSessionAsync } from "expo-web-browser";

----

const createSessionFromUrl = async (url: string) => {
  try {
    const { params, errorCode } = getQueryParams(url);

    if (errorCode) throw new Error(errorCode);
    const { secret, userId } = params;

    if (!secret || !userId) return;

    return await account.createSession(userId, secret);
  } catch (error) {
    console.error("Error creating session from URL:", error);
    throw error;
  }
};

  signWithOAuth: async (provider: OAuthProvider) => {
    const url = await account.createOAuth2Session(
      provider,
      "myCoolAppwriteApp://(authenticated)",
      "myCoolAppwriteApp://auth",
      ["openid", "profile"]
    );

    if (!url) throw new Error("Failed to create OAuth2 session");

    const res = await openAuthSessionAsync(
      url.toString(),
      "myCoolAppwriteApp://home"
    );

    if (res.type === "success") {
      const { url } = res;

      if (!url) throw new Error("Failed to create session from URL");

      await createSessionFromUrl(url);
    }
  },

@Nizam-shan
Copy link

Nizam-shan commented Mar 29, 2025 via email

@subhodeep2005s
Copy link

I having same issue
Error 400

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

Type

general_argument_invalid

@ammarfaris
Copy link

appwrite/appwrite#9262 was merged but then reverted due to issues during QA. We'll need to fix the issues with another PR.

@stnguyen90 so what's the solution now?

@solomonojox
Copy link

Has anyone gotten a solution yet?

@VARN0R
Copy link

VARN0R commented May 25, 2025

...
export async function login() {
  try {
  
    const redirectUri = Linking.createURL("/");

    console.log("Redirect URI:", redirectUri);

    const response = await account.createOAuth2Token(
      OAuthProvider.Google,
      redirectUri
    );
...

When launching the project via expo, everything works and is displayed in the console:
Redirect URI: exp://192.168.100.8:8082/--/

And with the native build for Android, error 400 and console output:
Redirect URI: com.varn0r.findroute:///

Maybe this will help you solve the problem somehow.🙏

@mnkyjs
Copy link

mnkyjs commented May 26, 2025

I found this article quiet helpful and was able to enable OIDC Provider (Keycloak) and get everything to work.

https://bishwajeet-parhi.medium.com/i-built-an-auth-template-powered-by-react-native-and-appwrite-4a0b7ee90ba6

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

9 participants