Table of Contents

OAuth Authorization

To use OAuth authorization in connectors in your program, you need to register several services:

// Connecting the password storage for access to StockSharp WebAPI.
ConfigManager.RegisterService<ICredentialsProvider>(new DefaultCredentialsProvider());
//ConfigManager.RegisterService<ICredentialsProvider>(new TokenCredentialsProvider("%token%"));

// Connecting the service provider for access to StockSharp WebAPI
ConfigManager.RegisterService<IApiServiceProvider>(new ApiServiceProvider());
                           
// OAuth authorization service that will be used by connectors
ConfigManager.RegisterService<IOAuthProvider>(new OAuthProvider());
//ConfigManager.RegisterService<IOAuthProvider>(new WebApiOAuthProvider());

There are two implementation options for ICredentialsProvider:

  1. DefaultCredentialsProvider - loads StockSharp account data from a local file. Prior authorization is required. For example, through the Installer.

  2. TokenCredentialsProvider - passes the token directly from the code. No secret file is required on the machine. The token is obtained from https://stocksharp.ru/profile/:

    Profile

There are two implementation options for IOAuthProvider:

  1. WebApiOAuthProvider - for console applications where no authorization window display is required.

  2. OAuthProvider - for WPF applications where an authorization window needs to be displayed:

    OAuth Start