csweb api authentication

Discussions about syncing data via Bluetooth, Dropbox, FTP, and using CSWeb
Post Reply
wis
Posts: 2
Joined: November 14th, 2019, 1:46 am

csweb api authentication

Post by wis » November 14th, 2019, 2:29 am

Hi Everyone

I have trouble authenticating to csweb using API in csweb from terminal with curl.

Curl command entered:

Code: Select all

curl -i -X POST URL/csweb/api/token -d "grant_type=password" -u username:password
Response:

Code: Select all

HTTP/1.1 400 Bad Request
Date: Thu, 14 Nov 2019 06:58:33 GMT
Server: Apache/2.4.39 (Win64) PHP/7.2.18
X-Powered-By: PHP/7.2.18
Cache-Control: no-store, private
Content-Length: 100
Connection: close
Content-Type: application/json

{"type":"error","status":400,"code":"invalid_client","message":"The client credentials are invalid"}
Please help with authentication.

Thanks

josh
Posts: 1988
Joined: May 5th, 2014, 12:49 pm
Location: Washington DC

Re: csweb api authentication

Post by josh » November 14th, 2019, 6:46 am

The token endpoint expects JSON content containing the username and password. Try something like the following:

Code: Select all

curl -H 'Content-Type: application/json' -X POST -d '{"client_id":"cspro_android","client_secret":"cspro","grant_type":"password","username":"username","password":"password"}' http://www.mycsweb.com/api/token
You should get a response like:

Code: Select all

{access_token":"c736f2206138c61d0e242a4518e1327a9c99afa9","expires_in":3600,"token_type":"Bearer","scope":null,"refresh_token":"9691e6e0c12d5afba51af52efd5e5ba2gabd7c3a"}
You can then use the access_token in the authorization header for future requests. With the above response the header would be:

Code: Select all

Authorization: Bearer c736f2206138c61d0e242a4518e1327a9c99afa9
The CSWeb REST API is documented in the file www/csweb/src/api/app/swagger.json. If you haven't used Swagger before they have some nice online tools for viewing Swagger specifications. Try https://swagger.io/tools/swagger-ui/.

wis
Posts: 2
Joined: November 14th, 2019, 1:46 am

Re: csweb api authentication

Post by wis » November 14th, 2019, 1:01 pm

Thanks very Josh.

It worked, now I can play around with the rest of the API's.

Thanks.

Karan
Posts: 1
Joined: November 16th, 2019, 4:07 am

Re: csweb api authentication

Post by Karan » November 16th, 2019, 4:23 am

hi there,
this is karan from india , i would like to know something about csweb , somebody help me for solving their problems which i face like,
when i want to use csweb option into "deploy application" there it is asking "usename & password" . guys i don't understand which usename or password it is asking , if i use my this site username & password then it give error massage like given below...
Doc1.docx
(120.13 KiB) Downloaded 9 times

Regards
Karan.

josh
Posts: 1988
Joined: May 5th, 2014, 12:49 pm
Location: Washington DC

Re: csweb api authentication

Post by josh » November 16th, 2019, 11:19 am

Please start a new topic rather than responding to someone elses unrelated post and please just post your question once (I deleted the other post in tools).

Please see the help on synchronization that describes the different server options: Dropbox, CSWeb and FTP: https://www.csprousers.org/help/CSPro/s ... ation.html

More details on how to set up a CSWeb server can be found in the help for CSWeb: https://www.csprousers.org/help/CSWeb/

Post Reply