Example #1
0
        /// <summary>
        /// Create an OAuth token provider to authenticate against ArcGIS Online
        /// </summary>
        /// <param name="clientId">The Client Id from your API access section of your application from developers.arcgis.com</param>
        /// <param name="clientSecret">The Client Secret from your API access section of your application from developers.arcgis.com</param>
        /// <param name="serializer">Used to (de)serialize requests and responses</param>
        public ArcGISOnlineAppLoginOAuthProvider(String clientId, String clientSecret, ISerializer serializer = null)
        {
            if (String.IsNullOrWhiteSpace(clientId) || String.IsNullOrWhiteSpace(clientSecret))
            {
                System.Diagnostics.Debug.WriteLine("ArcGISOnlineAppLoginOAuthProvider not initialized as client Id/secret not supplied.");
                return;
            }

            Serializer = serializer ?? SerializerFactory.Get();
            if (Serializer == null)
            {
                throw new ArgumentNullException("serializer", "Serializer has not been set.");
            }
            OAuthRequest = new GenerateOAuthToken(clientId, clientSecret);

            _httpClient = HttpClientFactory.Get();

            System.Diagnostics.Debug.WriteLine("Created TokenProvider for " + RootUrl);
        }
        internal ArcGISOnlineAppLoginOAuthProvider(Func <ILog> log, string clientId, string clientSecret, ISerializer serializer = null)
        {
            if (string.IsNullOrWhiteSpace(clientId))
            {
                throw new ArgumentNullException(nameof(clientId), "clientId is null.");
            }

            if (string.IsNullOrWhiteSpace(clientSecret))
            {
                throw new ArgumentNullException(nameof(clientSecret), "clientSecret is null.");
            }

            Serializer   = serializer ?? SerializerFactory.Get();
            OAuthRequest = new GenerateOAuthToken(clientId, clientSecret);
            _httpClient  = HttpClientFactory.Get();

            _logger = log() ?? LogProvider.For <ArcGISOnlineAppLoginOAuthProvider>();
            _logger.DebugFormat("Created new token provider for {0}", RootUrl);
        }