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 theOptimizely 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 theOptimizely 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 – AppKeyvalue (same as above).
- appSecret – Secretvalue (same as above).
 
- baseUrl – 
 
- Configure the Authentication method, for simplicity, it should be Basic, and put yourappKeyasUsernameandappSecretasPassword.
 
- Start 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.
 
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/v2Updated about 2 months ago
