public void Authenticate()
        {
            string responseData = null;
            //			var urlRegex = new Regex(@"^(ht|f)tp(s?)\:\/\/[0-9a-zA-Z]([-.\w]*[0-9a-zA-Z])*(:(0-9)*)*(\/?)([a-zA-Z0-9\-\.\?\,\'\/\\\+&%\$#_]*)?$");
            var urlRegex = new Regex(@"^(ht|f)tp(s?)\:\/\/[0-9a-zA-Z]([-.\w]*[0-9a-zA-Z])*(:(0-9)*)*(\/?)");
            var match    = urlRegex.Match(_credentials.TokenUrl);

            if (match.Success)
            {
                _client.BaseAddress    = match.Value;
                _client.EndpointMethod = _credentials.TokenUrl.Replace(_client.BaseAddress, string.Empty);
            }

            // https://docs.microsoft.com/en-us/linkedin/shared/authentication/authorization-code-flow?context=linkedin/context

            _client.AddParameter("response_type", "code");
            _client.AddParameter("client_id", _credentials.ConsumerKey);
            _client.AddParameter("redirect_uri", _credentials.CallbackUri);
            _client.AddParameter("state", _credentials.State);
            _client.AddParameter("scope", _credentials.Scope);

            responseData = _client.Get();

            if (responseData != null)
            {
                var tokenResponse = _serializationUtility.Deserialize <TokenResponse>(responseData);

                if (!string.IsNullOrEmpty(tokenResponse.error))
                {
                    throw new Exception($"Authentication Error: {tokenResponse.error} - {tokenResponse.error_description}");
                }

                _credentials.AccessToken = tokenResponse.access_token;
            }
        }
Exemplo n.º 2
0
        public string Analyze(string posterUrl, List <VisualFeature> visualFeatures = null, List <Detail> details = null, Language language = Language.undefined)
        {
            // https://[location].api.cognitive.microsoft.com/vision/v1.0/analyze[?visualFeatures][&details][&language]

            _restClient.EndpointMethod = $"/{BASE_METHOD}/{API_VERSION}/analyze";

            _restClient.AddParameters("visualFeatures", visualFeatures?.Select(item => item.ToString()));
            _restClient.AddParameters("details", details?.Select(item => item.ToString()));

            if (language != Language.undefined)
            {
                _restClient.AddParameter("language", language.ToString());
            }

            return(_restClient.Post($"{{\"url\":\"{posterUrl}\"}}"));
        }