HomeDev guideRecipesAPI Reference
Dev guideUser GuidesLegal TermsNuGetDev CommunityOptimizely AcademySubmit a ticketLog In
Dev guide

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)

  1. Open your Optimizely CMS solution and install theOptimizely ContentGraph addon.
dotnet add Optimizely.ContentGraph.Cms
  1. 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

  1. Set access rights for contents

  1. Run the website and run theOptimizely Graph content synchronization job.

Retrieve restricted content

Postman

  1. Import https://cg.optimizely.com/app/swagger/swagger.json to a Postman collection.
  2. Set up variables for the collection:
    • baseUrlhttps://cg.optimizely.com.
    • appKeyAppKey value (same as above).
    • appSecretSecret value (same as above).
  1. Configure the Authentication method, for simplicity, it should be Basic, and put your appKey as Username and appSecret as Password.
  1. Start query restricted content items with headers: cg-username and cg-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