realm / realm-dart

Realm is a mobile database: a replacement for SQLite & ORMs.
Apache License 2.0
768 stars 88 forks source link

AppException: could not find PEM formatted data in the provided public key #1529

Closed zohaib304 closed 8 months ago

zohaib304 commented 8 months ago

What happened?

I encountered an issue while using the MongoDB Realm SDK in my Flutter application for authentication using JWT tokens. When attempting to authenticate using credentials.jwt(token)

Repro steps

I consistently receive the following error message: “AppException: could not find PEM formatted data in the provided public key”.

Version

1.9.0

What Atlas Services are you using?

Atlas Device Sync

What type of application is this?

Flutter Application

Client OS and version

Android 9

Code snippets

User loggedInUser =
        await app.logIn(Credentials.jwt(token));

Stacktrace of the exception/crash you're getting

AppException: could not find PEM formatted data in the provided public key, status code: 401

Relevant log output

No response

sync-by-unito[bot] commented 8 months ago

➤ PM Bot commented:

Jira ticket: RDART-952

nirinchev commented 8 months ago

Per the error message, it looks like the public key you configured in the App Services dashboard is invalid.

zohaib304 commented 8 months ago

Thanks for pointing. I have resolved the above issue, and now there is a new exception.

I/flutter ( 9627): 2024-02-28T16:40:44.368788: [ERROR] Realm: App: log_in_with_credentials failed: 401 message: crypto/rsa: verification error I/flutter ( 9627): AppException: crypto/rsa: verification error, status code: 401

nirinchev commented 8 months ago

This appears to be a server side exception - is there anything in the server logs related to it?

zohaib304 commented 8 months ago

Received an AuthErrorwith the message "crypto/rsa: verification error".

nirinchev commented 8 months ago

Looks like a misconfiguration of the JWT auth provider. If you file a ticket on https://support.mongodb.com, the team should be able to assist you with it.

I'm closing this as we don't believe this is an issue with the flutter SDK.