示例#1
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);
        }
        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;
        }
        public static async Task <Imgur> CreateOAuth2AuthenticatedImgurClient()
        {
            var settings       = VariousFunctions.LoadTestSettings();
            var authentication = new OAuth2Authentication(settings.ClientId, settings.ClientSecret, false);
            await OAuthHelpers.GetAccessToken(authentication, settings);

            return(new Imgur(authentication));
        }
示例#4
0
        public static async Task <OAuth2Authentication> GetAccessToken(OAuth2Authentication authentication, TestSettings settings)
        {
            authentication.AuthorizeWithToken(settings.AccessToken, settings.RefreshToken, 3600, settings.AuthorizedUsername);
            await authentication.RefreshTokens();

            settings.AccessToken  = authentication.AccessToken;
            settings.RefreshToken = authentication.RefreshToken;
            VariousFunctions.SaveTestSettings(settings);

            return(authentication);
        }
示例#5
0
        public async Task TestCodeAuth()
        {
            var settings = VariousFunctions.LoadTestSettings();

            // Create a new OAuth2 Authentication
            var oAuth2Authentication = new OAuth2Authentication(settings.ClientId, settings.ClientSecret, false);
            var authorizationUrl     = oAuth2Authentication.CreateAuthorizationUrl(OAuth2Type.Code, "dicks");
            var code = "1234";

            try
            {
                await oAuth2Authentication.AuthorizeWithCode(code);
            }
            catch (ImgurResponseFailedException exception)
            {
                Assert.AreEqual(exception.ImgurResponse.Data.ErrorDescription, "Refresh token doesn't exist or is invalid for the client");
            }
        }
示例#6
0
        public async Task TestPinAuth()
        {
            var settings = VariousFunctions.LoadTestSettings();

            // Create a new OAuth2 Authentication
            var oAuth2Authentication = new OAuth2Authentication(settings.ClientId, settings.ClientSecret, false);
            var authorizationUrl     = oAuth2Authentication.CreateAuthorizationUrl(OAuth2Type.Pin, "dicks");

            Assert.AreNotEqual("", authorizationUrl);
            var pin = "1234";

            try
            {
                await oAuth2Authentication.AuthorizeWithPin(pin);
            }
            catch (ImgurResponseFailedException exception)
            {
                Assert.AreEqual(exception.ImgurResponse.Data.ErrorDescription, "Invalid Pin");
            }
        }
示例#7
0
        public void Finished(OAuth2Authentication auth, NSError error)
        {
            if (error != null)
            {
                //InvokeOnMainThread(() => new UIAlertView("Error", "Could not sign in.\nError: " + error.LocalizedDescription, null, "Ok", null).Show());
                InvokeOnMainThread(() => new UIAlertView("Login Failed", "The social network login failed for your account", null, "Ok", null).Show());
                HideLoadingView();
                CrashReporter.Report(new Exception(error.LocalizedDescription));
                return;
            }

            ShowLoadingView("Getting some user data...");

            UserTrackingReporter.TrackUser(Constant.CATEGORY_LOGIN, "Google login successful");

            AppSettings.LoginType = (int)LoginType.Google;
            AppSettings.UserToken = GetMd5Hash(md5Hash, SignIn.SharedInstance.UserEmail);
            AppSettings.UserEmail = SignIn.SharedInstance.UserEmail;
            AppSettings.UserType  = "";

            QueryPlus query = QueryPlus.QueryForPeopleGetWithUserId(SignIn.SharedInstance.UserId);

            SignIn.SharedInstance.PlusService.ExecuteQuery(query, GooglePlusPersonQueryCompleted);
        }
        public Authentication_UnitTests()
        {
            _authSettings = new AuthenticationSettings()
            {
                EnvClientID     = "MOCK_CLIENTID",
                EnvUserName     = "******",
                EnvUserPassword = "******",
                EnvClientSecret = "MOCK_CLIENTSECRET",
                Note            = "MockNote",
                OAuth2Endpoint  = "http://mock/",
                Scopes          = new List <string>()
                {
                    "mock_scope"
                }
            };

            Environment.SetEnvironmentVariable("MOCK_CLIENTID", "mockClientId");
            Environment.SetEnvironmentVariable("MOCK_USERNAME", "mockUsername");
            Environment.SetEnvironmentVariable("MOCK_USERPASS", "mockPassword");
            Environment.SetEnvironmentVariable("MOCK_CLIENTSECRET", "mockClientSecret");

            _basicAuth  = new BasicAuthentication(_authSettings);
            _oauth2Auth = new OAuth2Authentication(_authSettings);
        }
 public OAuthExpiredException(OAuth2Authentication authentication, string message, Exception innerException)
     : base(message, innerException)
 {
     Authentication = authentication;
 }
示例#10
0
 public OAuthExpiredException(OAuth2Authentication authentication, string message)
     : base(message)
 {
     Authentication = authentication;
 }
示例#11
0
 public OAuthExpiredException(OAuth2Authentication authentication)
 {
     Authentication = authentication;
 }