public void GetAuthorizationCodeViaUserAgentAndRequestProtectedResource()
        {
            //TODO: webrequest mocken
            // diesen dann mit "Pseudo"-Auth-Code ausstatten, die SetToken(server, incommingRequest) => resoruceOwner
            // und die WebRequest.Authorize(server, resourceOwner) anschubsen
            // dabei müssen die UserCredentials richtig gesetzt sein

            var resourceOwnertmp = ResourceOwners.GetResourceOwner(_resourceOwnerName);
            var servertmp        = ServersWithAuthorizationCode.GetServerWithAuthorizationCode(_clientId, _authorizationRequestUri, _accessTokenRequestUri, _redirectionUri);

            var mockContext = new Mock <IWebOperationContext> {
                DefaultValue = DefaultValue.Mock
            };

            mockContext.SetupAllProperties();
            var context = mockContext.Object;

            context.IncomingRequest.UriTemplateMatch.RequestUri = _redirectionUri;
            context.IncomingRequest.UriTemplateMatch.QueryParameters.Add("code", "Splx10BeZQQYbYS6WxSbIA");
            context.IncomingRequest.UriTemplateMatch.QueryParameters.Add("state", servertmp.Guid.ToString() + "_" + resourceOwnertmp.Guid.ToString());
            var tuple = context.GetCredentialsFromAuthorizationRedirect();

            var server        = tuple.Item1;
            var resourceOwner = tuple.Item2;

            server.Should().Be(servertmp);
            resourceOwner.Should().Be(resourceOwner);


            var webRequest = resourceOwner.GetSignedRequestFor(server, "http://example.com/ProtectedResource");;

            //Test ob WebRequest richtig unterschrieben wurde

            Assert.Fail("Test is not completed yet");
        }
Example #2
0
        public static Tuple <ServerWithAuthorizationCode, ResourceOwner> GetCredentialsFromAuthorizationRedirect(this IWebOperationContext context)
        {
            var code  = context.IncomingRequest.UriTemplateMatch.QueryParameters.Get("code");
            var state = context.IncomingRequest.UriTemplateMatch.QueryParameters.Get("state");

            if (string.IsNullOrEmpty(code))
            {
                throw new InvalidAuthorizationRequestException("the query parameters 'code' is not set.");
            }

            if (string.IsNullOrEmpty(state))
            {
                throw new InvalidAuthorizationRequestException("the query parameters 'state' is not set.");
            }

            if (!state.Contains("_"))
            {
                throw new InvalidAuthorizationRequestException("the query parameters 'state' must be of type '<GUID of Server>_<GUID of ResourceOwner>'");
            }
            var states = state.Split('_');

            var server        = ServersWithAuthorizationCode.GetServerWithAuthorizationCode(new Guid(states[0]));
            var resourceOwner = ResourceOwners.GetResourceOwner(new Guid(states[1]));

            var token = Tokens.GetToken(server, resourceOwner);

            token.AuthorizationCode = code;

            return(new Tuple <ServerWithAuthorizationCode, ResourceOwner>(server, resourceOwner));
        }
Example #3
0
        public void GetResourceOwner()
        {
            ResourceOwners.CleanUpForTests();
            ResourceOwners.Add("user1");
            ResourceOwners.Add("user2");

            var resourceOwner = ResourceOwners.GetResourceOwner("user1");

            resourceOwner.Name.Should().Be("user1");
            ResourceOwners.GetResourceOwner(resourceOwner.Guid).Should().NotBeNull();

            var resourceOwnerNull = ResourceOwners.GetResourceOwner("foo");

            resourceOwnerNull.Should().BeNull();
            ResourceOwners.GetResourceOwner(Guid.NewGuid()).Should().BeNull();
        }
Example #4
0
        public void DisposeAndLoad()
        {
            ResourceOwners.CleanUpForTests();
            ResourceOwners.Add("user1");
            ResourceOwners.Add("user2");

            ResourceOwners.SaveToIsoStore();
            ResourceOwners.LoadFromIsoStore();

            var resourceOwner = ResourceOwners.GetResourceOwner("user1");

            Assert.IsNotNull(resourceOwner);
            Assert.AreEqual("user1", resourceOwner.Name);

            var resourceOwnerNull = ResourceOwners.GetResourceOwner("foo");

            Assert.IsNull(resourceOwnerNull);
        }
        public void CreateServerAndUsersAndGetCorrectRedirectToAuthorizationRequest()
        {
            // Spec v2-22 4.1.1

            var resourceOwner = ResourceOwners.GetResourceOwner(_resourceOwnerName);
            var server        = ServersWithAuthorizationCode.GetServerWithAuthorizationCode(_clientId, _authorizationRequestUri,
                                                                                            _accessTokenRequestUri,
                                                                                            _redirectionUri);

            var mockContext = new Mock <IWebOperationContext> {
                DefaultValue = DefaultValue.Mock
            };

            mockContext.SetupAllProperties();
            resourceOwner.AuthorizesMeToAccessTo(server).Should().BeFalse();
            var context = mockContext.Object;

            context.RedirectToAuthorization(server, resourceOwner);

            context.OutgoingResponse.StatusCode.Should().Be(HttpStatusCode.Redirect);
            context.OutgoingResponse.Location.Should().NotBeNullOrEmpty();
        }