class NativeClient
A SharePoint OAuth client class that provides endpoints for native client authentication relative to the current request context.
/tf/active/vicechatdev/SPFCsync/venv/lib64/python3.11/site-packages/office365/sharepoint/oauth/native_client.py
6 - 22
moderate
Purpose
NativeClient is a specialized Entity class designed to handle native client authentication in SharePoint environments. It provides methods to authenticate using MicrosoftOnlineCredentials and manages OAuth endpoints for native applications. This class is part of the SharePoint OAuth authentication flow and is used when applications need to authenticate users through native client mechanisms rather than web-based flows.
Source Code
class NativeClient(Entity):
"""Gets endpoints for native client authentication relative to current request."""
def __init__(self, context):
super(NativeClient, self).__init__(
context, ResourcePath("SP.OAuth.NativeClient")
)
def authenticate(self):
"""Authentication module to handle MicrosoftOnlineCredentials."""
qry = ServiceOperationQuery(self, "Authenticate")
self.context.add_query(qry)
return self
@property
def entity_type_name(self):
return "SP.OAuth.NativeClient"
Parameters
| Name | Type | Default | Kind |
|---|---|---|---|
bases |
Entity | - |
Parameter Details
context: A SharePoint client context object that maintains the connection state, authentication credentials, and request handling for SharePoint operations. This context is required for all Entity-based operations and is passed to the parent Entity class along with the resource path 'SP.OAuth.NativeClient'.
Return Value
The constructor returns a NativeClient instance initialized with the provided context and configured with the resource path 'SP.OAuth.NativeClient'. The authenticate() method returns self (the NativeClient instance) to enable method chaining. The entity_type_name property returns the string 'SP.OAuth.NativeClient' which identifies the SharePoint entity type.
Class Interface
Methods
__init__(self, context)
Purpose: Initializes a new NativeClient instance with the provided SharePoint context and sets up the resource path for OAuth native client operations
Parameters:
context: SharePoint client context object that manages the connection, authentication, and request execution
Returns: None (constructor)
authenticate(self) -> NativeClient
Purpose: Initiates the authentication process for native client using MicrosoftOnlineCredentials by creating and adding a service operation query to the context
Returns: Returns self (the NativeClient instance) to enable method chaining
entity_type_name(self) -> str
property
Purpose: Returns the SharePoint entity type name identifier for this OAuth native client
Returns: The string 'SP.OAuth.NativeClient' which identifies this entity type in SharePoint
Attributes
| Name | Type | Description | Scope |
|---|---|---|---|
context |
ClientContext | The SharePoint client context inherited from Entity that manages connection state, authentication, and query execution | instance |
resource_path |
ResourcePath | The resource path 'SP.OAuth.NativeClient' inherited from Entity that identifies the SharePoint resource endpoint | instance |
Dependencies
office365
Required Imports
from office365.runtime.paths.resource_path import ResourcePath
from office365.runtime.queries.service_operation import ServiceOperationQuery
from office365.sharepoint.entity import Entity
Usage Example
from office365.sharepoint.client_context import ClientContext
from office365.runtime.auth.user_credential import UserCredential
from office365.sharepoint.oauth.native_client import NativeClient
# Create SharePoint context with credentials
site_url = 'https://yourtenant.sharepoint.com/sites/yoursite'
username = 'user@yourtenant.onmicrosoft.com'
password = 'your_password'
ctx = ClientContext(site_url).with_credentials(UserCredential(username, password))
# Create and use NativeClient for authentication
native_client = NativeClient(ctx)
native_client.authenticate()
ctx.execute_query()
# The authentication endpoints are now available through the native_client object
Best Practices
- Always ensure the context object is properly initialized with valid credentials before creating a NativeClient instance
- Call execute_query() on the context after calling authenticate() to actually execute the authentication request
- The authenticate() method returns self, allowing for method chaining if needed
- This class is designed for native client scenarios (desktop/mobile apps) rather than web applications
- Handle authentication errors appropriately as network or credential issues may cause failures
- The NativeClient inherits from Entity, so it follows the SharePoint entity lifecycle and query execution pattern
- Do not instantiate multiple NativeClient instances for the same context unless necessary, as each may trigger separate authentication flows
Tags
Similar Components
AI-powered semantic similarity - components with related functionality:
-
class SharePointRestClient 67.7% similar
-
class AuthenticationContext 63.3% similar
-
class SharePointClient 61.3% similar
-
class ClientContext 60.8% similar
-
class Authentication 59.8% similar