public static IBaseSpaceClient CreateWebRequestClient()
        {
            // construct the settings object from the config file
            string apiKey = ConfigurationManager.AppSettings.Get("basespace:api-key");
            string apiSecret = ConfigurationManager.AppSettings.Get("basespace:api-secret");
            string apiUrl = ConfigurationManager.AppSettings.Get("basespace:api-url");
            string webUrl = ConfigurationManager.AppSettings.Get("basespace:web-url");
            string version = ConfigurationManager.AppSettings.Get("basespace:api-version");

            var authentication = new OAuth2Authentication(apiKey, apiSecret);

            var settings = new BaseSpaceClientSettings
                               {
                                   Authentication = authentication,
                                   BaseSpaceApiUrl = apiUrl,
                                   BaseSpaceWebsiteUrl = webUrl,
                                   Version = version
                               };

            // first retrieve the verification code
            var verificationCode = FetchVerificationCode(settings);

            // initiate the steps that validate the verification code
            LaunchBrowser(verificationCode.VerificationWithCodeUri);

            // poll for the access token
            AccessToken accessToken = FetchAccessToken(verificationCode, settings);

            // TODO Removed OAuth v2
            var client = new BaseSpaceClient(settings, new RequestOptions());

            // build and return the client
            return client;
        }
Exemple #2
0
        public static IBaseSpaceClient CreateWebRequestClient()
        {
            // construct the settings object from the config file
            string apiKey    = ConfigurationManager.AppSettings.Get("basespace:api-key");
            string apiSecret = ConfigurationManager.AppSettings.Get("basespace:api-secret");
            string apiUrl    = ConfigurationManager.AppSettings.Get("basespace:api-url");
            string webUrl    = ConfigurationManager.AppSettings.Get("basespace:web-url");
            string version   = ConfigurationManager.AppSettings.Get("basespace:api-version");

            var authentication = new OAuth2Authentication(apiKey, apiSecret);

            var settings = new BaseSpaceClientSettings
            {
                Authentication      = authentication,
                BaseSpaceApiUrl     = apiUrl,
                BaseSpaceWebsiteUrl = webUrl,
                Version             = version
            };

            // first retrieve the verification code
            var verificationCode = FetchVerificationCode(settings);

            // initiate the steps that validate the verification code
            LaunchBrowser(verificationCode.VerificationWithCodeUri);

            // poll for the access token
            AccessToken accessToken = FetchAccessToken(verificationCode, settings);

            // TODO Removed OAuth v2
            var client = new BaseSpaceClient(settings, new RequestOptions());

            // build and return the client
            return(client);
        }
Exemple #3
0
        public static IBaseSpaceClient CreateWebRequestClient()
        {
            // construct the settings object from the config file
            string apiKey    = SettingsDict["basespace:api-key"].ToString();
            string apiSecret = SettingsDict["basespace:api-secret"].ToString();
            string apiUrl    = SettingsDict["basespace:api-url"].ToString();
            string webUrl    = SettingsDict["basespace:web-url"].ToString();
            string version   = SettingsDict["basespace:api-version"].ToString();
            var    settings  = new BaseSpaceClientSettings()
            {
                AppClientId = apiKey, AppClientSecret = apiSecret, BaseSpaceApiUrl = apiUrl, BaseSpaceWebsiteUrl = webUrl, Version = version
            };

            // first retrieve the verification code
            var verificationCode = FetchVerificationCode(settings);

            // initiate the steps that validate the verification code
            LaunchBrowser(verificationCode.VerificationWithCodeUri);

            // poll for the access token
            AccessToken accessToken = FetchAccessToken(verificationCode, settings);

            var client = new BaseSpaceClient(settings, new RequestOptions(apiUrl, accessToken.TokenString));

            // build and return the client
            return(client);
        }
 // Note: prefer access through the Client property!
 public static IBaseSpaceClient CreateRealClient()
 {
     string apiKey = SettingsDict["basespace:api-key"].ToString();
     string apiSecret = SettingsDict["basespace:api-secret"].ToString();
     string apiUrl = SettingsDict["basespace:api-url"].ToString();
     string webUrl = SettingsDict["basespace:web-url"].ToString();
     string version = SettingsDict["basespace:api-version"].ToString();
     string authCode = SettingsDict["basespace:api-authcode"].ToString();
     var settings = new BaseSpaceClientSettings(){AppClientId = apiKey, AppClientSecret = apiSecret, BaseSpaceApiUrl = apiUrl, BaseSpaceWebsiteUrl = webUrl, Version =version};
     IBaseSpaceClient iBaseSpaceClient = new BaseSpaceClient(settings, new RequestOptions(apiUrl, authCode));
     return iBaseSpaceClient;
 }
Exemple #5
0
        private static VerificationCode FetchVerificationCode(BaseSpaceClientSettings settings)
        {
            VerificationCode verificationCode = new VerificationCode();
            var verificationUri = verificationCode.BuildRequestUri(settings);

            if ((verificationUri == null) || string.IsNullOrEmpty(verificationUri.AbsoluteUri))
            {
                return(null); // TODO: throw exception
            }
            string jsonResponse = HttpPost(verificationUri, string.Empty);

            verificationCode.FromJson(jsonResponse);

            return(verificationCode);
        }
        // Note: prefer access through the Client property!
        public static IBaseSpaceClient CreateRealClient()
        {
            string apiKey    = SettingsDict["basespace:api-key"].ToString();
            string apiSecret = SettingsDict["basespace:api-secret"].ToString();
            string apiUrl    = SettingsDict["basespace:api-url"].ToString();
            string webUrl    = SettingsDict["basespace:web-url"].ToString();
            string version   = SettingsDict["basespace:api-version"].ToString();
            string authCode  = SettingsDict["basespace:api-authcode"].ToString();
            var    settings  = new BaseSpaceClientSettings()
            {
                AppClientId = apiKey, AppClientSecret = apiSecret, BaseSpaceApiUrl = apiUrl, BaseSpaceWebsiteUrl = webUrl, Version = version
            };
            IBaseSpaceClient iBaseSpaceClient = new BaseSpaceClient(settings, new RequestOptions(apiUrl, authCode));

            return(iBaseSpaceClient);
        }
        // Note: prefer access through the Client property!
        protected virtual IBaseSpaceClient CreateRealClient()
        {
            //string apiKey = ConfigurationManager.AppSettings.Get("basespace:api-key");
            //string apiSecret = ConfigurationManager.AppSettings.Get("basespace:api-secret");
            string apiUrl = ConfigurationManager.AppSettings.Get("basespace:api-url");
            string webUrl = ConfigurationManager.AppSettings.Get("basespace:web-url");
            string version = ConfigurationManager.AppSettings.Get("basespace:api-version");

            var settings = new BaseSpaceClientSettings
                {
                    Authentication = GetAuthentication(),
                    BaseSpaceApiUrl = apiUrl,
                    BaseSpaceWebsiteUrl = webUrl,
                    Version = version
                };

            return new BaseSpaceClient(settings);
        }
        // Note: prefer access through the Client property!
        public static IBaseSpaceClient CreateRealClient()
        {
            string apiKey = ConfigurationManager.AppSettings.Get("basespace:api-key");
            string apiSecret = ConfigurationManager.AppSettings.Get("basespace:api-secret");
            string apiUrl = ConfigurationManager.AppSettings.Get("basespace:api-url");
            string webUrl = ConfigurationManager.AppSettings.Get("basespace:web-url");
            string version = ConfigurationManager.AppSettings.Get("basespace:api-version");
            string accessToken = ConfigurationManager.AppSettings.Get("basespace:api-accesstoken");
            var settings = new BaseSpaceClientSettings
                {
                    Authentication = new OAuth2Authentication(apiKey, apiSecret),
                    BaseSpaceApiUrl = apiUrl,
                    BaseSpaceWebsiteUrl = webUrl,
                    Version = version
                };

            IBaseSpaceClient iBaseSpaceClient = new BaseSpaceClient(settings, new RequestOptions(apiUrl, new OAuth2Authentication(accessToken)));
            return iBaseSpaceClient;
        }
        // Note: prefer access through the Client property!
        protected virtual IBaseSpaceClient CreateRealClient()
        {
            //string apiKey = ConfigurationManager.AppSettings.Get("basespace:api-key");
            //string apiSecret = ConfigurationManager.AppSettings.Get("basespace:api-secret");
            string apiUrl        = ConfigurationManager.AppSettings.Get("basespace:api-url");
            string apiBillingUrl = ConfigurationManager.AppSettings.Get("basespace:api-billing-url");
            string webUrl        = ConfigurationManager.AppSettings.Get("basespace:web-url");
            string version       = ConfigurationManager.AppSettings.Get("basespace:api-version");

            var settings = new BaseSpaceClientSettings
            {
                Authentication         = GetAuthentication(),
                BaseSpaceApiUrl        = apiUrl,
                BaseSpaceBillingApiUrl = apiBillingUrl,
                BaseSpaceWebsiteUrl    = webUrl,
                Version = version
            };

            return(new BaseSpaceClient(settings));
        }
        public static IBaseSpaceClient CreateWebRequestClient()
        {
            // construct the settings object from the config file
            string apiKey = SettingsDict["basespace:api-key"].ToString();
            string apiSecret = SettingsDict["basespace:api-secret"].ToString();
            string apiUrl = SettingsDict["basespace:api-url"].ToString();
            string webUrl = SettingsDict["basespace:web-url"].ToString();
            string version = SettingsDict["basespace:api-version"].ToString();
            var settings = new BaseSpaceClientSettings() { AppClientId = apiKey, AppClientSecret = apiSecret, BaseSpaceApiUrl = apiUrl, BaseSpaceWebsiteUrl = webUrl, Version = version };

            // first retrieve the verification code
            var verificationCode = FetchVerificationCode(settings);

            // initiate the steps that validate the verification code
            LaunchBrowser(verificationCode.VerificationWithCodeUri);

            // poll for the access token
            AccessToken accessToken = FetchAccessToken(verificationCode, settings);

            var client = new BaseSpaceClient(settings, new RequestOptions(apiUrl, accessToken.TokenString));

            // build and return the client
            return client;
        }
        private static VerificationCode FetchVerificationCode(BaseSpaceClientSettings settings)
        {
            VerificationCode verificationCode = new VerificationCode();
            var verificationUri = verificationCode.BuildRequestUri(settings);
            if ((verificationUri == null) || string.IsNullOrEmpty(verificationUri.AbsoluteUri))
                return null; // TODO: throw exception

            string jsonResponse = HttpPost(verificationUri, string.Empty);
            verificationCode.FromJson(jsonResponse);

            return verificationCode;
        }
        private static AccessToken FetchAccessToken(VerificationCode verificationCode, BaseSpaceClientSettings settings)
        {
            AccessToken accessToken = null;
            Int32 interval = verificationCode.Interval * 1000;

            // TODO: use the new "await" instead of looping
            // TODO: we should have a hard stop at some useful limit of time
            while (accessToken == null)
            {
                Thread.Sleep(interval);

                try
                {
                    // TODO: wrap in try-catch with System.Net.WebException handler
                    Uri authUri = accessToken.BuildRequestUri(verificationCode, settings);
                    string jsonResponse = HttpPost(authUri, string.Empty);
                    //string response = HttpPost(authVerificationCode.VerificationWithCodeUri.AbsoluteUri, string.Empty);
                    // TODO: convert to using 200 response
                    if ((!string.IsNullOrEmpty(jsonResponse) && !jsonResponse.Contains("DOCTYPE")))
                    {
                        accessToken = new AccessToken();
                        accessToken.FromJson(jsonResponse);
                        //// TODO: add sensitivity to return value, e.g., 404
                        //switch(response.getClientResponseStatus())
                        //{
                        //    case BAD_REQUEST:
                        //        AccessToken token = mapper.readValue(response.getEntity(string.class), AccessToken.class);
                        //        if (token.getError().equalsIgnoreCase(ACCESS_DENIED))
                        //        {
                        //            throw new AccessDeniedException();
                        //        }
                        //        break;
                        //    case OK:
                        //        token = mapper.readValue(response.getEntity(string.class), AccessToken.class);
                        //        accessToken = token.getAccessToken();
                        //}
                    }

                }
                catch (System.Net.WebException)
                {
                    // ignore these exceptions
                    continue;
                    //throw;
                }
            }
            return accessToken;
        }
Exemple #13
0
        private static AccessToken FetchAccessToken(VerificationCode verificationCode, BaseSpaceClientSettings settings)
        {
            AccessToken accessToken = null;
            Int32       interval    = verificationCode.Interval * 1000;

            // TODO: use the new "await" instead of looping
            // TODO: we should have a hard stop at some useful limit of time
            while (accessToken == null)
            {
                Thread.Sleep(interval);

                try
                {
                    // TODO: wrap in try-catch with System.Net.WebException handler
                    Uri    authUri      = accessToken.BuildRequestUri(verificationCode, settings);
                    string jsonResponse = HttpPost(authUri, string.Empty);
                    //string response = HttpPost(authVerificationCode.VerificationWithCodeUri.AbsoluteUri, string.Empty);
                    // TODO: convert to using 200 response
                    if ((!string.IsNullOrEmpty(jsonResponse) && !jsonResponse.Contains("DOCTYPE")))
                    {
                        accessToken = new AccessToken();
                        accessToken.FromJson(jsonResponse);
                        //// TODO: add sensitivity to return value, e.g., 404
                        //switch(response.getClientResponseStatus())
                        //{
                        //    case BAD_REQUEST:
                        //        AccessToken token = mapper.readValue(response.getEntity(string.class), AccessToken.class);
                        //        if (token.getError().equalsIgnoreCase(ACCESS_DENIED))
                        //        {
                        //            throw new AccessDeniedException();
                        //        }
                        //        break;
                        //    case OK:
                        //        token = mapper.readValue(response.getEntity(string.class), AccessToken.class);
                        //        accessToken = token.getAccessToken();
                        //}
                    }
                }
                catch (System.Net.WebException)
                {
                    // ignore these exceptions
                    continue;
                    //throw;
                }
            }
            return(accessToken);
        }