Ejemplo n.º 1
0
        private String GetAuthToken()
        {
            log.Debug("Getting auth token...");
            String    baseUrl    = this.options.AuthBaseUrl ?? this.options.BaseUrl;
            ApiClient authClient = new ApiClient(baseUrl + "/auth/v3");

            ((Configuration)authClient.Configuration).BasePath = baseUrl + "/auth/v3";
            authClient.Configuration.ApiKey.Add("x-api-key", this.options.ApiKey);
            authClient.Configuration.DefaultHeader.Add("x-api-key", this.options.ApiKey);
            authClient.RestClient.AddDefaultHeader("x-api-key", this.options.ApiKey);

            String encoded       = Convert.ToBase64String(Encoding.GetEncoding("ISO-8859-1").GetBytes(this.options.ClientId + ":" + this.options.ClientSecret));
            String authorization = "Basic " + encoded;

            AuthenticationApi authApi = new AuthenticationApi((Genesys.Internal.Authentication.Client.Configuration)authClient.Configuration);

            ApiResponse <DefaultOAuth2AccessToken> response = authApi.RetrieveTokenWithHttpInfo(
                "password", authorization, null, "*",
                this.options.ClientId, null, this.options.Username, this.options.Password);

            CookieManager.SaveCookies(new Uri(this.options.BaseUrl + "/auth/v3/"), response.Headers);

            return(response.Data.AccessToken);
        }