Skip to content
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

React-Native logout error /api/account/logout #18334

Closed
1 task done
nev-21 opened this issue Dec 2, 2023 · 2 comments
Closed
1 task done

React-Native logout error /api/account/logout #18334

nev-21 opened this issue Dec 2, 2023 · 2 comments
Assignees
Milestone

Comments

@nev-21
Copy link

nev-21 commented Dec 2, 2023

Is there an existing issue for this?

  • I have searched the existing issues

Description

When click on logout button an error appear on the dotnet server:

'OpenIddictValidationAspNetCoreHandler' which cannot be used for SignOutAsync. 
The registered sign-out schemes are: Identity.Application, Identity.External, Identity.TwoFactorRememberMe, Identity.TwoFactorUserId, OpenIddict.Server.AspNetCore.
System.InvalidOperationException: The authentication handler registered for scheme 'OpenIddict.Validation.AspNetCore'
is 'OpenIddictValidationAspNetCoreHandler' which cannot be used for SignOutAsync.
The registered sign-out schemes are: Identity.Application, Identity.External, Identity.TwoFactorRememberMe, 
Identity.TwoFactorUserId, OpenIddict.Server.AspNetCore.

image

Reproduction Steps

  1. create a new abp project with react native
    abp new Test -u none -m react-native -d ef -dbms MySQL

  2. run it: https://docs.abp.io/en/abp/latest/Getting-Started-React-Native?Tiered=No
    There is one additional step that is not mentioned in the tutorial (the port on Environment.js should match the dotnet port)

  3. run dotnet, run react-native, execute Android studio virtual smartphone

  4. login, then click logout (a toast error will appear, and the error is visible on dotnet server too)

Expected behavior

no error should appear.

I think /api/account/logout purpose is to delete cookies on browser? or am I wrong?. So if react-native doesnt need cookies (cause it is a mobile app) and it is doing password flow (ROPC) it should call revoke access-token instead of logout.

Actual behavior

an error appear on logout.

Regression?

No response

Known Workarounds

workaround:

The error appear when this code is executed:
https://github.com/abpframework/abp/blob/7.4.2/templates/app/react-native/src/api/AccountAPI.js#L34-L38

I tried to replicate in postman, the same error appear:

image

When i change the Authorization from Bearer to No-auth or Basic (with any data) the error dissappear
image

So, the error appear cause in react native, the Logout endpoint is called cause the interceptor adds the access token to the call.
https://github.com/abpframework/abp/blob/7.4.2/templates/app/react-native/src/interceptors/APIInterceptor.js

The saga erase the token after logout is called, maybe call it before call logout make it work (but i dont know if that makes sense, cause the logout endpoint is supposed to erase cookies but it is a native app)
https://github.com/abpframework/abp/blob/7.4.2/templates/app/react-native/src/store/sagas/AppSaga.js

Version

7.4.2

User Interface

React Native

Database Provider

EF Core (Default)

Tiered or separate authentication server

None (Default)

Operation System

Windows (Default)

Other information

The docs are strange too. They say react-native apps do auth-code flow, but the code says grant_type: 'password' so i think this should be clarified.

https://docs.abp.io/en/commercial/latest/getting-started-react-native#add-application-to-database

Since ABP version 7.4 react native uses [authorization code flow](https://datatracker.ietf.org/doc/html/rfc8252), 
you need to add an application to the database for the mobile application. 
ABP will create a client for the mobile application. 
You can use the DbMigrator project to add an application to the database. 
You can find the DbMigrator project in the aspnet-core/src/ProjectName.DbMigrator folder.
@masum-ulu
Copy link
Member

masum-ulu commented Feb 8, 2024

Hi @nev-21 commercial part is using authorization_code flow for now we'll convert open source too. Document belongs to commercial not open source

This is open source react native template document

As far as I understand you are using open source template not pro template. I'm checking and try to reporduce error. I'll solve in this issue.

@masum-ulu masum-ulu modified the milestones: 8.1-preview, 8.0-patch Feb 12, 2024
@masum-ulu masum-ulu mentioned this issue Feb 14, 2024
2 tasks
@masum-ulu masum-ulu added hold Taken progress, but needs to wait something. and removed in-progress labels Feb 14, 2024
@masum-ulu
Copy link
Member

We'll change auth method to authorization_code flow in the future. If u want to keep move with password flow this PR will solve your problem

@masum-ulu masum-ulu removed the hold Taken progress, but needs to wait something. label Feb 14, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

4 participants