Back

Microsoft Oauth error Param "code" is not optional

  • 0
  • Flutter
Kinyapiplele
28 Jul, 2023, 12:41

I've seen this post in github but nothing mentioning Microsoft auth https://github.com/appwrite/appwrite/issues/2591

I solved some errors with the redirect url but now I'm getting the error Param "code" is not optional and not sure how to fix it. I'm currently using the cloud version of appwrite

TL;DR
Title: Microsoft Oauth error - Param "code" is not optional TLDR: User is experiencing an error with Microsoft Oauth in their Flutter app using Appwrite. They are receiving the error message "Param 'code' is not optional" and are unsure how to fix it. They have tried modifying the redirect URL but without success. Solution: There is currently no known solution to this issue. The user is advised to upvote the corresponding ticket and consider self-hosting if they have a self-hosted instance. A potential solution can be found in the linked Discord thread, which provides possible fixes for similar authentication provider errors.
Binyamin
28 Jul, 2023, 13:56

The error will appear for most auth providers, as when returning to Appwrite url, the code will be missing. So what I suggest is to upvote the issue, and if you have a self-hosted instance you can try the solution you can find here https://discord.com/channels/564160730845151244/1110920292685053972/1110920292685053972

Kinyapiplele
28 Jul, 2023, 14:13

Thank you! I Will try self hosting and Will upvote the ticket

Drake
28 Jul, 2023, 18:53

what's in the url of the page your're on?

Kinyapiplele
28 Jul, 2023, 19:43

The URL from the redirect Uri

Drake
28 Jul, 2023, 19:51

would you please share the URL of the page you're on when you see that error?

Drake
29 Jul, 2023, 14:34

I mean after you log in, you end up on the page that says error param code is not optional. What's the URL of that page?

Kinyapiplele
29 Jul, 2023, 14:41

It's the first URL i sent...

Drake
29 Jul, 2023, 14:45

Is that really the full url? No query string params?

Kinyapiplele
29 Jul, 2023, 14:46

Yup

Drake
29 Jul, 2023, 14:49

That's really weird...can you try the flow again from a browser with the browser dev tools on so you can capture the network logs for the entire flow. Maybe one of the network logs will show some sort of error (from Microsoft)

Drake
29 Jul, 2023, 14:58

Ohhhhhhhh what's your flutter code that calls the createOAuth2Session()

Kinyapiplele
29 Jul, 2023, 15:03

Not sure how's the best way to paste the code but here it goes:

import 'package:appwrite/appwrite.dart';

Future microsoftAuth2Session() async { Client client = Client(); Account account = Account(client);

client .setEndpoint('https://cloud.appwrite.io/v1') // Your API Endpoint .setProject('64c3a7469667bd1b8dd5') // Your project ID ; Future result = account.createOAuth2Session( provider: 'microsoft', success: 'https://cloud.appwrite.io/v1/account/sessions/oauth2/callback/microsoft/64c3a7469667bd1b8dd5', );

result.then((response) { print(response); }).catchError((error) { print(error.response); }); }

Drake
29 Jul, 2023, 15:04

So that success youre passing in isn't quite right...is this a flutter mobile app?

Kinyapiplele
29 Jul, 2023, 15:04

Right now I'm trying it in a web session. Currently in flutterflow Should the success url be a url from the flutter app? I put the cloud.appwrite.... url cause otherwise I got this other error: Error 400 Invalid success: URL host must be one of: localhost, cloud.appwrite.io

Drake
29 Jul, 2023, 15:18

The success url should redirect the user back to your app. Typically, devs have to set up this auth page and the success url should point to this page: https://github.com/appwrite/sdk-for-flutter/tree/master#web

Kinyapiplele
29 Jul, 2023, 16:19

Thank you for the link

Reply

Reply to this thread by joining our Discord

Reply on Discord

Need support?

Join our Discord

Get community support by joining our Discord server.

Join Discord

Get premium support

Join Appwrite Pro and get email support from our team.

Learn more