Пример #1
0
 /// <summary>
 /// Creates a new token manager without pre-shared access token and refresh token.
 /// </summary>
 /// <param name="configuration">The client configuration containing the base URL, among others</param>
 /// <param name="appId">The app id of this client, in the form of {customer_id}-{client_id}</param>
 /// <param name="appSecret">The app secret of this client</param>
 /// <param name="accessToken">The pre-shared access token (typically of the Sync User) or an already existing access token from a previous session</param>
 /// <param name="refreshToken">The pre-shared refresh token (typically of the Sync User) or an already existing refresh token from a previous session</param>
 /// <param name="expiresOn">The expiration date of the access token</param>
 public OAuthTokenManager(HQAPIClientConfiguration configuration, string appId, string appSecret, string accessToken, string refreshToken, DateTime expiresOn)
     : this(configuration, appId, appSecret)
 {
     CurrentAccessToken  = accessToken;
     CurrentRefreshToken = refreshToken;
     ExpiresOn           = expiresOn;
 }
Пример #2
0
        static void Main(string[] args)
        {
            // Create a client configuration with an OAuth Token Manager
            var config  = new HQAPIClientConfiguration("https://api.hqlabs.de");
            var manager = config.CreateOAuthTokenManager("AppId", "AppSecret",
                                                         "SyncUser-AccessToken",
                                                         "SyncUser-RefreshToken",
                                                         DateTime.UtcNow.AddSeconds(2500000));

            // Register a callback for when the token was refreshed
            manager.TokenRefreshed += Manager_TokenRefreshed;

            // Create the client with the configuration
            var client = new HQAPIClient(config);

            // Get the details about the currently authenticated user.
            var user = client.MeV1_GetAsync().Result;

            // Create and put a new UserReporting Example
            var newReproting = new CreateUserReportingAPISample();

            newReproting.CreateUserReportingApi(client);

            // Get and create Company Example
            var Company = new CompanyAPISample();

            Company.CompanyAPI(client);
        }
Пример #3
0
        /// <summary>
        /// Creates a new token manager without pre-shared access token and refresh token.
        /// </summary>
        /// <param name="configuration">The client configuration containing the base URL, among others</param>
        /// <param name="appId">The app id of this client, in the form of {customer_id}-{client_id}</param>
        /// <param name="appSecret">The app secret of this client</param>
        public OAuthTokenManager(HQAPIClientConfiguration configuration, string appId, string appSecret)
        {
            if (!appId.Contains("-"))
            {
                throw new ArgumentException("AppId needs to be in the format customerId-clientId");
            }

            Configuration = configuration;
            AppId         = appId;
            CustomerId    = int.Parse(AppId.Split('-')[0]);
            AppSecret     = appSecret;
        }
Пример #4
0
 /// <summary>
 /// Creates a new token manager without pre-shared access token and refresh token.
 /// </summary>
 /// <param name="configuration">The client configuration containing the base URL, among others</param>
 /// <param name="appId">The app id of this client, in the form of {customer_id}-{client_id}</param>
 /// <param name="appSecret">The app secret of this client</param>
 /// <param name="accessToken">The pre-shared access token (typically of the Sync User) or an already existing access token from a previous session</param>
 public OAuthTokenManager(HQAPIClientConfiguration configuration, string appId, string appSecret, string accessToken)
     : this(configuration, appId, appSecret)
 {
     CurrentAccessToken = accessToken;
 }
Пример #5
0
 /// <summary>
 /// Updates the configuration of this client, used by all future requests. The base url cannot be updated this way.
 /// </summary>
 /// <param name="configuration"></param>
 public void SetConfiguration(HQAPIClientConfiguration configuration)
 {
     _configuration = configuration;
 }
Пример #6
0
 /// <summary>
 /// Creates a new client with the provided client configuration.
 /// </summary>
 /// <param name="configuration"></param>
 public HQAPIClient(HQAPIClientConfiguration configuration) : this(configuration.BaseUrl)
 {
     _configuration = configuration;
 }