-
Notifications
You must be signed in to change notification settings - Fork 3.8k
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
🐛 Bug Report: Code 400 when clicking "Cancel" during a LinkedIn Oauth login #2591
Comments
@superseby2 please share the URL of the Appwrite link you were redirected to. |
Here it is @eldadfux |
Bit of an update with some debug That's the error once I am redirecter by Linkedin
|
@superseby2 can you please share the code you used to initiate the login? What's passed in the failure URL? This should probably redirect to the failure URL. need to figure out why it didn't. Your code would help. |
Thx @lohanidamodar for looking at the problem. The code is pretty straightforward Tried without a failure URI and with. Does not change a thing Again here is the URI where I am redirected when I clicked Cancel at Linkedin auth page. https:///v1/account/sessions/oauth2/callback/linkedin/61d9932a0eda26b103b0?error=user_cancelled_login&error_description=The+user+cancelled+LinkedIn+login&state=%7B%22success%22%3A%22http%3A%5C%2F%5C%2Flocalhost%3A3000%5C%2Fapp-techie%22%2C%22failure%22%3A%22https%3A%5C%2F%5C%2F%5C%2Fv1%5C%2Fauth%5C%2Foauth2%5C%2Ffailure%22%7D I cannot see any "code" param in the URL but appwrite expects it. From my understanding the redirect to the failure URL should happen right after but because of this error, this is not happening. |
+1 on this. Having the same issue with the Discord provider in 0.15 |
+1 - having the same issue with the Facebook provider - hitting Cancel on the auth screen produces the same Appwrite error. Discord post - https://discord.com/channels/564160730845151244/564175717521424424/1007600938267181116 |
Adding on to this. Not really familiar with the AW codebase, but it looks like the redirecting to a failure URL does indeed work, it's just the fact that the "code" param is required. Looked into the code a tiny bit and it looks like https://github.com/appwrite/appwrite/blob/master/app/controllers/api/account.php#L363 -> L422/432 is where it's at. If the code prop were to be made optional, or even detecting it as not present, and subsequently redirecting to the failure URL, it should be sorted. But then again, I'm really not familiar with the codebase, and not PHP either, so take my suggestions with a grain of salt :) Someone like @lohanidamodar probably know it a lot better than me |
+1 on this. Having the same issue with the Github provider in 1.3.4 |
I am also getting this exact error just when attempting to login with GitHub (using Nextjs & Next-Auth)
I firstly have this login with github function: export const signInWithGithub = async () => {
const session = await getServerSession(authOptions);
if (session) {
const userId = session.user?.id;
const dynamicRoute = `/board/${userId}`;
return account.createOAuth2Session('github', `http:https://localhost:3000/${dynamicRoute}`, 'http:https://localhost:3000');
} else {
//
}
}; Then my login component: import { signIn } from 'next-auth/react';
//...
function Login() {
async function loginWithGithub() {
try {
await signIn('github');
signInWithGithub();
} catch (error) {
throw new Error(`Something went wrong with your login: ${error}`);
} finally {
//...
}
};
//...
}; Then this function to set up an appwrite provider: import { Profile } from 'next-auth';
import { OAuthConfig } from 'next-auth/providers';
const appwriteProvider = (options: {
baseUrl: string;
}): OAuthConfig<Profile> => {
const { baseUrl } = options;
return {
id: 'appwrite',
name: 'Appwrite',
type: 'oauth',
version: '2.0',
accessTokenUrl: `${baseUrl}/v1/auth/oauth2/token`,
authorization: `${baseUrl}/api/auth/callback/appwrite`,
profileUrl: `${baseUrl}/v1/account`,
profile: (profile: any) => {
return {
id: profile.$id,
name: profile.name,
email: profile.email,
image: profile.avatar,
};
},
}
};
export default appwriteProvider; Lastly, my authOptions: export const authOptions: NextAuthOptions = {
//...
providers: [
GithubProvider({
clientId: getGitHubCredentials().clientId,
clientSecret: getGitHubCredentials().clientSecret,
}),
appwriteProvider({
baseUrl: 'http:https://localhost:3000',
}),
],
//...
callbacks: {
//...
async redirect(params: { url: string; baseUrl: string}) {
return params.url;
},
}
} EDIT: (06/09/2023)My error was with the authorization URL in my GitHub OAuth app. I am now still having other unrelated issues... But that solved THIS issue. |
+1 Same with Discord Oauth2 |
👟 Reproduction steps
👍 Expected behavior
👎 Actual Behavior
🎲 Appwrite version
Different version (specify in environment)
💻 Operating system
Linux
🧱 Your Environment
Appwrite 0.12
👀 Have you spent some time to check if this issue has been raised before?
🏢 Have you read the Code of Conduct?
The text was updated successfully, but these errors were encountered: