コード例 #1
0
        //[TestCase("r2-ref")]
        public async Task MobileConnectWebInterfaceShouldWorkEndToEndWithCache(string configKey)
        {
            RestClient      restClient     = new RestClient();
            IDiscoveryCache cache          = new ConcurrentDiscoveryCache();
            IDiscovery      discovery      = new GSMA.MobileConnect.Discovery.Discovery(cache, restClient);
            IAuthentication authentication = new GSMA.MobileConnect.Authentication.Authentication(restClient);

            var testConfig             = TestConfig.GetConfig(configKey);
            MobileConnectConfig config = new MobileConnectConfig()
            {
                DiscoveryUrl = testConfig.DiscoveryUrl,
                ClientId     = testConfig.ClientId,
                ClientSecret = testConfig.ClientSecret,
                RedirectUrl  = testConfig.RedirectUrl
            };

            MobileConnectRequestOptions blankOptions  = new MobileConnectRequestOptions();
            MobileConnectWebInterface   mobileConnect = new MobileConnectWebInterface(discovery, authentication, config);

            //Attempt discovery
            var request = new HttpRequestMessage();
            var status  = await mobileConnect.AttemptDiscoveryAsync(request, testConfig.ValidMSISDN, null, null, true, blankOptions);

            Assert.AreEqual(MobileConnectResponseType.StartAuthorization, status.ResponseType);

            var session         = status.SDKSession;
            var encryptedMsisdn = status.DiscoveryResponse.ResponseData.subscriber_id;
            var state           = "zmxncbvalskdjfhgqpwoeiruty";
            var nonce           = "qpwoeirutyalskdjfhgzmxncbv";

            //Start Authorization
            request = new HttpRequestMessage();
            status  = await mobileConnect.StartAuthorization(request, session, encryptedMsisdn, state, nonce, blankOptions);

            Assert.AreEqual(MobileConnectResponseType.Authorization, status.ResponseType);

            //Inconclusive at this point because the sandbox no longer allows us to follow redirects easily
            Assert.Inconclusive("Can't follow redirects in sandbox");

            //Authorization
            request = new HttpRequestMessage();
            var redirectedUrl = await FollowRedirects(status.Url, _basicRequestHeaders, testConfig.RedirectUrl);

            Assert.That(() => redirectedUrl.AbsoluteUri.StartsWith(testConfig.RedirectUrl));
            Assert.AreEqual(state, HttpUtils.ExtractQueryValue(redirectedUrl.Query, "state"));

            //Handle auth redirect and request token
            request = new HttpRequestMessage();
            status  = await mobileConnect.HandleUrlRedirectAsync(request, redirectedUrl, session, state, nonce);

            Assert.AreEqual(MobileConnectResponseType.Complete, status.ResponseType);
            Assert.IsNotEmpty(status.TokenResponse.ResponseData.AccessToken);
        }
コード例 #2
0
        public async Task MobileConnectWebInterfaceShouldWorkEndToEndHeadlessWithRevoke(string configKey)
        {
            RestClient             restClient     = new RestClient();
            ICache                 cache          = null;
            IDiscoveryService      discovery      = new GSMA.MobileConnect.Discovery.DiscoveryService(cache, restClient);
            IAuthenticationService authentication = new GSMA.MobileConnect.Authentication.AuthenticationService(restClient);
            IIdentityService       identity       = new GSMA.MobileConnect.Identity.IdentityService(restClient);
            IJWKeysetService       jwks           = new GSMA.MobileConnect.Authentication.JWKeysetService(restClient, cache);

            var testConfig             = TestConfig.GetConfig(configKey);
            MobileConnectConfig config = new MobileConnectConfig()
            {
                DiscoveryUrl = testConfig.DiscoveryUrl,
                ClientId     = testConfig.ClientId,
                ClientSecret = testConfig.ClientSecret,
                RedirectUrl  = testConfig.RedirectUrl
            };

            MobileConnectRequestOptions blankOptions  = new MobileConnectRequestOptions();
            MobileConnectWebInterface   mobileConnect = new MobileConnectWebInterface(discovery, authentication, identity, jwks, config);

            //Attempt discovery
            var request = new HttpRequestMessage();
            var status  = await mobileConnect.AttemptDiscoveryAsync(request, testConfig.ValidMSISDN, null, null, true, false, blankOptions);

            Assert.AreEqual(MobileConnectResponseType.StartAuthentication, status.ResponseType, $"{status.ErrorCode} - {status.ErrorMessage}");

            var discoveryResponse = status.DiscoveryResponse;
            var encryptedMsisdn   = status.DiscoveryResponse.ResponseData.subscriber_id;
            var state             = "zmxncbvalskdjfhgqpwoeiruty";
            var nonce             = "qpwoeirutyalskdjfhgzmxncbv";

            //Start Authorization
            var authOptions = new MobileConnectRequestOptions {
                Scope = "mc_authz", BindingMessage = "auth test", Context = "test"
            };

            request = new HttpRequestMessage();
            status  = await mobileConnect.RequestHeadlessAuthenticationAsync(request, discoveryResponse, encryptedMsisdn, state, nonce, authOptions);

            Assert.AreEqual(MobileConnectResponseType.Complete, status.ResponseType, $"{status.ErrorCode} - {status.ErrorMessage}");
            Assert.IsNotEmpty(status.TokenResponse.ResponseData.AccessToken);
            Assert.IsNotEmpty(status.TokenResponse.ResponseData.IdToken);

            //Revoke Token
            status = await mobileConnect.RevokeTokenAsync(request, status.TokenResponse.ResponseData.AccessToken, null, discoveryResponse);

            Assert.AreEqual(MobileConnectResponseType.TokenRevoked, status.ResponseType, $"{status.ErrorCode} - {status.ErrorMessage}");
        }
        public void Setup()
        {
            _restClient = new RestClient();
            _cache      = new ConcurrentCache();

            _testConfig = TestConfig.GetConfig(TestConfig.DEFAULT_TEST_CONFIG);
            _config     = new MobileConnectConfig()
            {
                DiscoveryUrl = _testConfig.DiscoveryUrl,
                ClientId     = _testConfig.ClientId,
                ClientSecret = _testConfig.ClientSecret,
                RedirectUrl  = _testConfig.RedirectUrl,
            };

            _mobileConnect = new MobileConnectWebInterface(_config, _cache, _restClient);
        }
コード例 #4
0
        public void Setup()
        {
            _restClient     = new RestClient();
            _cache          = new ConcurrentDiscoveryCache();
            _discovery      = new GSMA.MobileConnect.Discovery.Discovery(_cache, _restClient);
            _authentication = new GSMA.MobileConnect.Authentication.Authentication(_restClient);

            _testConfig = TestConfig.GetConfig(TestConfig.DEFAULT_TEST_CONFIG);
            _config     = new MobileConnectConfig()
            {
                DiscoveryUrl = _testConfig.DiscoveryUrl,
                ClientId     = _testConfig.ClientId,
                ClientSecret = _testConfig.ClientSecret,
                RedirectUrl  = _testConfig.RedirectUrl,
            };

            _mobileConnect = new MobileConnectWebInterface(_discovery, _authentication, _config);
        }
コード例 #5
0
 public void Setup()
 {
     _testConfig = TestConfig.GetConfig(TestConfig.DEFAULT_TEST_CONFIG);
     Setup(new RestClient());
 }
コード例 #6
0
 public void Setup()
 {
     _testConfig = TestConfig.GetConfig(TestConfig.DEFAULT_TEST_CONFIG);
     Setup(new RestClient(TimeSpan.FromSeconds(20)));
 }