CSharp/SPO.Samples/SPO.ModernAuthentication/Helpers/ServicePrincipalAuthenticationManager.cs
/// <summary>
/// Method to Get SPO Client Context.
/// </summary>
/// <param name="web">SPO Web Url.</param>
/// <param name="tenantId">SPO Tenant ID.</param>
/// <param name="clientId">AAD App Client ID.</param>
/// <param name="clientCertificate">AAD Client Certificate.</param>
/// <returns>SPO Client Context.</returns>
Method to Get SPO Client Context.
Method to Get SPO Client Context .
public ClientContext GetContext(Uri web, string tenantId, string clientId, X509Certificate2 clientCertificate)
        {
            var context = new ClientContext(web);
            context.ExecutingWebRequest += (sender, e) =>
            {
                string accessToken = this.EnsureAccessTokenAsync(new Uri($"{web.Scheme}://{web.DnsSafeHost}"), tenantId, clientId, clientCertificate).GetAwaiter().GetResult();
                e.WebRequestExecutor.RequestHeaders["Authorization"] = "Bearer " + accessToken;
            };
            return context;
        }
public ClientContext GetContext ( Uri web , string tenantId , string clientId , X509Certificate2 clientCertificate ) { var context = new ClientContext ( web ) ; context . ExecutingWebRequest += ( sender , e ) => { string accessToken = this . EnsureAccessTokenAsync ( new Uri ( $" { web . Scheme } :// { web . DnsSafeHost } " ) , tenantId , clientId , clientCertificate ) . GetAwaiter ( ) . GetResult ( ) ; e . WebRequestExecutor . RequestHeaders [ " " ] = " " + accessToken ; } ; return context ; }
Method to Get SPO Client Context.
Method to Get SPO Client Context .
SPO Client Context.
SPO Client Context .
web
Uri
SPO Web Url.
SPO Web Url .
tenantId
string
SPO Tenant ID.
SPO Tenant ID .
clientId
string
AAD App Client ID.
AAD App Client ID .
clientCertificate
X509Certificate2
AAD Client Certificate.
AAD Client Certificate .