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());
- DefaultCredentialsProvider and TokenCredentialsProvider implement the ICredentialsProvider interface.
- ApiServiceProvider implements the IApiServiceProvider interface.
OAuthProvider
implements the IOAuthProvider interface.
There are two implementation options for ICredentialsProvider:
DefaultCredentialsProvider - loads StockSharp account data from a local file. Prior authorization is required. For example, through the Installer.
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/:
There are two implementation options for IOAuthProvider:
WebApiOAuthProvider - for console applications where no authorization window display is required.
OAuthProvider - for WPF applications where an authorization window needs to be displayed: