fkoers
(Fkoers)
May 29, 2018, 11:13am
#1
I have problems to authenticate for rest-api service.
i configured the Application paramters as following:
cuba.webContextName = app-core
cuba.availableLocales = English|en
cuba.localeSelectVisible = false
cuba.anonymousSessionId = 002a9c13-8e06-af86-f829-cb5bf06b6ff6
cuba.rest.client.id = test
cuba.rest.client.secret = test
cuba.rest.anonymousEnabled = true
Swagger curl:
curl -X POST --header 'Content-Type: application/x-www-form-urlencoded' --header 'Accept: application/json' -d 'grant_type=password&username=test&password=test' 'http://localhost:8080/app/rest/v2/oauth/token'
i get the following message:
{
"error": "unauthorized",
"error_description": "Full authentication is required to access this resource"
}
i also tried it with basic authentication test:test dit also not work.
can someone help me?
zharenov
(Evgeniy Zharenov)
May 29, 2018, 12:04pm
#2
Hello, @fkoers !
You must add Authorization header with value
Basic dGVzdDp0ZXN0
where dGVzdDp0ZXN0 - it is test:test encoded in Base64
Here is the example app with REST API authorization.
Link to the doc: CUBA Platform. Developerâs Manual
1 Like
fkoers
(Fkoers)
May 29, 2018, 1:18pm
#3
Thank you for your fast response Evgeniy,
so now i do the following calls with swagger:
call 1 getToken:
curl -X POST --header âContent-Type: application/x-www-form-urlencodedâ --header âAccept: application/jsonâ --header âAuthorization: Basic dGVzdDp0ZXN0â -d âgrant_type=password&username=admin&password=adminâ âhttp://localhost:8080/app/rest/v2/oauth/token â
Or should i use âtest testâ as username and pasword. again?
response:
{
âerrorâ: âunauthorizedâ,
âerror_descriptionâ: âBad credentialsâ
}
call 2:
curl -X GET --header âAccept: application/jsonâ --header âAuthorization: Basic dGVzdDp0ZXN0â âhttp://localhost:8080/app/rest/v2/entities/workshop%24Client â
response {
âerrorâ: âunauthorizedâ,
âerror_descriptionâ: âAn Authentication object was not found in the SecurityContextâ
}
401
zharenov
(Evgeniy Zharenov)
May 29, 2018, 2:40pm
#4
You must set cuba.rest.client.id
and cuba.rest.client.secret
in web-app.properties (web module).
Auth request will return access token (it will be used in next queries, not test:test encoded in base64 ).
In the second query need to add header Authorization with value
Bearer [_access_token_]
For example,
Bearer c57c8e69-76cc-4e27-8780-50514cc30299
1 Like
fkoers
(Fkoers)
June 1, 2018, 7:09am
#5
Thanks Evgeniy, its working
1 Like
Iâm having the same issue and I did set both client_id & client_secret in app_properties