Making authenticated requests to Liferay 7.2
Making authenticated requests to Liferay 7.2
Overview
This article will describe how to make authenticated requests in Liferay 7.2 with Basic Authentication.
Configuration
First of all, you need to enable "Auto Login Basic Authentication Header".
Go to
Control Panel -> Configuration -> System Settings > API Authentication
.
Check the '
Enabled
' flag:Making the request
Let's say, you have some restricted document in Documents and Media, with the URL:
http://localhost:8080/documents/20123/35301/Liferay+DXP+7.2+Datasheet.pdf/4f069157-d409-577e-eda5-cf46b131b9cf
You can't access this link being not logged in, because it does not have View permissions for Guest.
So, you need to access this URL being logged in. For this you need to send HTTP Authorization header.
Command with basic authorization:
curl -H "Authorization: Basic [auth-string]" [url]
, where
auth-string
is encoded email:password pair.
To obtain the auth-string - run command:
openssl base64 <<< test@liferay.com:test
You'll get encoded string in response, sample:
dGVzdEBsaWZlcmF5LmNvbTp0ZXN0Cg==
Now you can run command, like:
curl --output Liferay_DXP_7.2.pdf -H "Authorization: Basic dGVzdEBsaWZlcmF5LmNvbTp0ZXN0Cg==" http://localhost:8080/documents/20123/35301/Liferay+DXP+7.2+Datasheet.pdf/4f069157-d409-577e-eda5-cf46b131b9cf
, where
--output Liferay_DXP_7.2.pdf
tells, that response should be saved to Liferay_DXP_7.2.pdf
file.
Comments
Post a Comment