Back

oAuth2 with native Java

  • 0
  • Android
  • Auth
Naos
13 Sep, 2024, 13:39

Im trying to get this going but no matter what I put in the redirect urls I keep getting the same error "URL Host must be one of: -list of web platforms added in appwrite-"

  • if I put them to "appwrite-callback-[projectid]://" I get an error from the appwrite server that it doesnt conform the my set web platform
  • if I put them to "null" it interprets them as empty / missing
  • If I just not set them it thinks I want to set the scopes variable as the redirect url and complains
  • "com.yourdomain.app://oauth2redirect", / doesnt work
  • Localhost doesnt work
  • etc public static void performOAuth(AppCompatActivity activity) { List<String> scopes = Arrays.asList("User.Read", "User.ReadBasic.All"); // Adjust scopes as needed account.createOAuth2Session( activity, OAuthProvider.MICROSOFT, null, null, scopes, new CoroutineCallback<>((result, error) -> { if (error != null) { error.printStackTrace(); return; } Log.d("Appwrite", result.toString()); }) ); }
TL;DR
Developers are discussing an issue with oAuth2 in Java Android SDK. The problem seems to be related to passing scopes as an array. The correct way to pass scopes in Java would be as shown in the provided code snippet. The issue is likely specific to the Android SDK and could potentially be a bug. The syntax for Java and JavaScript differs in this context. Ensure that the scopes are being passed correctly to avoid errors.
D5
15 Sep, 2024, 15:36

I think that the issue is permissions and also, have in mind that the order is important

Naos
15 Sep, 2024, 15:42

How? It works on web; Permissions are set on the appwrite console and thus correct;

What do you mean by order? This is almost a copy paste from the docs and it doesn't work

D5
15 Sep, 2024, 15:43

Java on web?

Naos
15 Sep, 2024, 15:43

No. My first code snippet is Java. My second one is a simple web app

I do the same thing on both. Web/ svelte works Android / Java doesnt

Naos
15 Sep, 2024, 15:44

Ofc adapting it to their respective sdks as it says in the docs

Naos
15 Sep, 2024, 15:45

Since it works in my web implementation all appwrite / Microsoft settings are good.

D5
15 Sep, 2024, 15:47

I think that the syntax for Java and JS is different. Anyways, If you're building an Android App, you don't need to specify any redirect URl, I think

Naos
15 Sep, 2024, 15:48

As I said in my first msg I've tried everything, null won't work, which I think might be another bug (: the urls are in fact not optional params

Naos
15 Sep, 2024, 15:48

Yes the syntax is different ... compare my first msg to the other one?

Naos
15 Sep, 2024, 15:50

I've tried to ask / find a working 0auth2 Java android sample but have yet to find one

Naos
15 Sep, 2024, 15:50

Though it could just ve the Microsoft provider

Naos
15 Sep, 2024, 15:55

So should I post this to the github?

D5
15 Sep, 2024, 15:57

From what I understood, the issue only happens with the android SDK?

Naos
15 Sep, 2024, 16:01

Yipyip

Naos
15 Sep, 2024, 16:02

Correct

Naos
15 Sep, 2024, 16:02

It passes the scopes wrong I'm suspecting

D5
15 Sep, 2024, 16:04

What scopes?

D5
15 Sep, 2024, 16:05

The code should look like this for android:

TypeScript
account.createOAuth2Session(
    OAuthProvider.Amazon, // provider
);

Do you really need the scopes?

Naos
15 Sep, 2024, 16:07

See my first msg ... it has it like that

Yes you do need scopes or you get another error;

Naos
15 Sep, 2024, 16:09

For Java android btw, it's not quite the same as kotlin

Naos
15 Sep, 2024, 16:18

The scopes should not be passed as an array like that; this is something appwrite is doing towards msft and I can

D5
16 Sep, 2024, 10:55

@Steven Do you know why does this happen?

Naos
16 Sep, 2024, 13:37

already had a chat with Steven, seems like a bug in the scope usage indeed

Naos
16 Sep, 2024, 13:37

Steven β€” Yesterday at 9:42 PM Hmm okay. Seems like maybe a bug in the SDK.

I don't think toString() here is the right approach https://github.com/appwrite/sdk-for-android/blob/85fac9dedd90eefe8407382cdd9f54b436862703/library/src/main/java/io/appwrite/services/Account.kt#L1212

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