HomeDev GuideRecipesAPI Reference
Dev GuideAPI ReferenceUser GuideGitHubNuGetDev CommunityOptimizely AcademySubmit a ticketLog In
Dev Guide

Authentication requests in C# SDK

Explains how to authenticate requests in the Optimizely Graph C# SDK using Single Key or Basic Authentication, and how each method affects which content your queries can access.

👍

Early access preview

This content is an early access preview and may change before general availability. Use the thumbs up or down at the end of this article to share feedback and help shape the final release.

The Optimizely Graph C# SDK supports two authentication methods. The authentication method determines which content your queries can return from Optimizely Graph.

Single Key Authentication

Single Key authentication is the default configuration. In this mode, queries automatically return only published content that is publicly available. You do not need to add status filters to your queries.

Use this mode for public websites where only published content should appear.

Example

var result = await _graphClient
    .QueryContent<BlogPostPage>()
    .Where(x => x.Author == "John Developer")
    .Limit(10)
    .GetAsContentAsync();

Use Single Key authentication when you want to:

  • Serve published content on a public-facing website
  • Avoid manually filtering content status in queries

Basic Authentication

Basic authentication provides access to all content, including drafts and unpublished items. Call UseBasicAuth() in the query chain before GetAsContentAsync().

var result = await _graphClient
    .QueryContent<BlogPostPage>()
    .Where(x => x.Author == "John Developer")
    .UseBasicAuth()
    .Limit(10)
    .GetAsContentAsync();

Use Basic authentication when you want to:

  • Preview unpublished content
  • Render draft content in preview environments
  • Control which content statuses your queries return

Security best practices

❗️

Important

Do not share API keys or secrets. If you contact Optimizely support about a query issue, provide the correlation-id returned in the response instead of sharing credentials.

Store credentials using environment variables or a secure secrets manager. Do not commit credentials to source-controlled configuration files such as appsettings.json.