Basic authentication from backend
How to use basic authentication of Optimizely CMS.
Prerequisites
- Optimizely CMS
- Optimizely Graph addon (only PaaS)
- Postman or cURL
CMS configuration
Setup (PaaS only)
- Open your Optimizely CMS solution and install the
Optimizely ContentGraph
addon.
dotnet add Optimizely.ContentGraph.Cms
- Update the
appsetting.json
file. (You should get this information from the Optimizely Support team).
"Optimizely": {
"ContentGraph": {
"GatewayAddress": "",
"AppKey": "",
"Secret": "",
"SingleKey": "",
"AllowSendingLog": "true",
"ContentVersionSyncMode": "All",
"SyncReferencingContents": "true",
"EnablePreviewTokens": "true"
}
},
Config
- Set access rights for contents
- Run the website and run the
Optimizely Graph content synchronization job
.
Retrieve restricted content
Postman
- Import https://cg.optimizely.com/app/swagger/swagger.json to a Postman collection.
- Set up variables for the collection:
- baseUrl –
https://cg.optimizely.com
. - appKey –
AppKey
value (same as above). - appSecret –
Secret
value (same as above).
- baseUrl –
- Configure the Authentication method, for simplicity, it should be
Basic
, and put yourappKey
asUsername
andappSecret
asPassword
.
- Start query restricted content items with headers:
cg-username
andcg-roles
:
Note
- cg-username – Optimizely CMS user.
- cg-roles – Optimizely CMS roles to access specific content items.
cURL
curl \
--request POST \
--user "$appKey:$secret" \
--header "Content-Type: application/json" \
--header "cg-roles: Everyone,Content Admins,Administrators" \
--header "cg-username: admin" \
--data '{"query":"{\n Content {\n items {\n Name\n Status\n }\n }\n}","variables":{}}' \
https://cg.optimizely.com/content/v2
Updated 3 months ago