Basic authentication from backend
How to use basic authentication of Optimizely Content Management System (CMS).
Configure Optimizely Graph to retrieve content from your CMS (PaaS) solution, including restricted content that requires authenticated access. Learn how to set up the ContentGraph addon, configure access rights, and query content using Postman or HTTP clients.
Prerequisites
- Optimizely Content Management System (CMS)
- Optimizely Graph addon (only PaaS)
- Postman or cURL
CMS configuration
Setup (PaaS only)
- Open your Optimizely CMS solution and install the
Optimizely ContentGraphaddon.
dotnet add Optimizely.ContentGraph.Cms- Update the
appsetting.jsonfile. (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. - Wait until the job finishes. Only after finishing the restricted content can be accessed.
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 –
AppKeyvalue (same as above). - appSecret –
Secretvalue (same as above).
- baseUrl –
- Configure the Authentication method, for simplicity, it should be
Basic, and put yourappKeyasUsernameandappSecretasPassword.
- Start to query restricted content items with headers:
cg-usernameandcg-roles:
Note
- cg-username – Optimizely CMS user.
- cg-roles – Optimizely CMS roles to access specific content items.
.HTTP
Make Http calls using the header code given.
POST {{graphDomain}}/content/v2
Content-Type: application/json
Authorization: Basic {{graphBase64EncodedToken}}
cg-roles: Administrators
{ "query" :"query { ProductPage { total } }" }Updated 2 days ago
