Fetch oauth2 login to use Rest API from web or from android mobile

Please help Jmix team and community members to answer your questions:

  • Jmix 2.2.1
  • Basic demo app from examples
  • Added rest api support

We are “”playing”” Jmix but we have some problems on oauth2 authentication …

Running a basic application our goal is to login and use some REST API like list some objects
from web and from mobile.

We can access to the rest api after login ( using JMIX application ) ed everithing is fine.
But how can we user REST API without JMIX Login ?

From web site we use JS and Fetch

We use Javascript
We use FetchApi as like this

// javascript fetch call to login
fetch(url, {
credentials : “include”,
method : “POST”,
mode : ‘cors’,
headers : {
“Content-Type” : “application/json”,
“Authorization” : 'Basic ’ + btoa(email + “:” + password),
‘Access-Control-Request-Method’ : ‘POST’,
},
// handle response
}).then(function(response) { …

How can we build a login ? using user and password ?
We dont want to use JMIX Vaadin GUI, because we develop a custom app web js/mobile android.

http://localhost:8080/oauth2/token ??
we are following your istructions :
Getting Started with REST :: Jmix Documentation (VER.2 )

curl --location ‘http://localhost:8080/oauth2/token
–header ‘Content-Type: application/x-www-form-urlencoded’
–header ‘Authorization: Basic WkdKdFkyMXZhV2g21ZVRwaN2JtOXZjSDE0V1ZwU2NtdHZlRzFHOg==’
data ‘grant_type=client_credentials’

Is there someting wrong ?
Is it possible to use Fetch to login and access the REST Api ?
Is there any example in JS or Android ?

thanks to all for the support

regards
Stefano

Hello,

Sample (OAuth2 + Jmix + React):

In the next update, we supported logging into the REST API using a login and password.

Regards,
Nikita

I think should be nice to have, as soon as possible in order
to replace Legacy web application.
Generally the Customer Web Interface cannot change.
We are in this Stack

old
Customer WEB GUI or Android App <----> (Customer Api) REST Api <----> Entity (Customer DB Access)

new
Customer WEB GUI or Android App <----> (Jmix) REST Api <----> Entity (Jmix)

So actually is not possible to use Jmix 2.2.0 to replace only RestApi backend ??

we dont use react
but Javascript and fetch function to send requests

do you have a Javascript example I can test ?
regards
Stefano

We currently don’t have a vanilla JavaScript example.

If you urgently need authorization using the grant_type password, take a look at these topics:

Discussions:

Regards,
Nikita