I am new to wappler and trying to build mobile app. I want to authenticate from my rest server, which require this curl for token -
POST {{Server URI}}
Authorization: Basic {{client_id}} {{client_secret}}
Content-Type: application/x-www-form-urlencoded
In order to make a POST request with cURL, you need to use the -X flag to specify the request method (POST in this case) and the -d flag to specify the body of the request (the username and password in this case).
The command should look something like this: curl -X POST -d “grant_type=password&username={{username}}&password={{password}}” {{Server URI}} -H “Authorization: Basic {{client_id}} {{client_secret}}” -H “Content-Type: application/x-www-form-urlencoded”
I don’t know if I understood what you said, but let’s wait for more answers.
Thanks @AdrianoLuiz for your guidance , I miscommunicated in my post. My question was how to configure this in wappler api action/data source? (this way i will get authentication token from rest server) and witch component, i should use api action/datasource?
This is not going to be exact to your needs as the grant_type is different, but if may be helpful to understand how others have setup oauth in Wappler. There’s four parts in different posts.
I have my own backend project which will be used in mobile app in wappler for all data/authenticate with rest api. Do I still need to make/host web data project to authenticate/get data in mobile app. (mobile app api action don’t have secret ket etc)
If your backend project already handles authentication and data, then you do not need to host anything for Wappler. You just create a mobile project and use Wappler to create the mobile app and connect it to your backend.
Where/How i should give clientid and secret, it is not available in mobile api action but available only in web app oauth?
This is the data, i should be using to get token:
POST {{Server URI}}
Authorization: Basic {{client_id}} {{client_secret}}
Content-Type: application/x-www-form-urlencoded
You can see your ss const is being converted using btoa() in the Authorization field. The btoa function is not standard in Wappler, so you’ll need to set up a custom formatter.
I would think your API Action would look something like this.
But same this is working in SC when data_type is form is selected. AC don’t have data_type = form and Sc giges same error if data_type is not json or text. (I think passing grant_type, username and password in body is problem, if data_type is not form)
I don’t think you are sending your Client ID and Client Secret in Authorization Header. That is probably why you’re getting a 401 unauthorized response.