Esempio n. 1
0
        /// <summary>
        /// Attempt to get and set an OAuth token with client id, username, and password
        /// </summary>
        public void LoginAsUser(string clientId, string username, string password)
        {
            if (string.IsNullOrEmpty(clientId))
            {
                throw new ApiException(400, "Missing required paramater clientId");
            }
            if (string.IsNullOrEmpty(username))
            {
                throw new ApiException(400, "Missing required paramater username");
            }
            if (string.IsNullOrEmpty(password))
            {
                throw new ApiException(400, "Missing required paramater password");
            }
            var token = Oauth.GetOauthToken("password",
                                            clientId,
                                            username: username,
                                            password: password);

            this.Configuration.AccessToken = token.AccessToken;
        }
Esempio n. 2
0
        /// <summary>
        /// Attempt to get and set an OAuth token with client id and secret
        /// </summary>
        public void Login(string clientId, string clientSecret)
        {
            if (string.IsNullOrEmpty(clientId))
            {
                throw new ApiException(400, "Missing required paramater clientId");
            }
            // Login as user if available
            if (!string.IsNullOrEmpty(this.Configuration.Username) &&
                !string.IsNullOrEmpty(this.Configuration.Password))
            {
                LoginAsUser(clientId, this.Configuration.Username, this.Configuration.Password);
                return;
            }
            // Must be logging in with id and secret
            if (string.IsNullOrEmpty(clientSecret))
            {
                throw new ApiException(400, "Missing required paramater clientSecret");
            }
            var token = Oauth.GetOauthToken("client_credentials",
                                            clientId,
                                            clientSecret: clientSecret);

            this.Configuration.AccessToken = token.AccessToken;
        }