Exemplo n.º 1
0
        public async Task UserSetupUrl()
        {
            // Construct a V1 immediate request
            Protocol       protocol         = Protocol.V11;
            OpenIdProvider provider         = this.CreateProvider();
            var            immediateRequest = new CheckIdRequest(protocol.Version, OPUri, DotNetOpenAuth.OpenId.AuthenticationRequestMode.Immediate);

            immediateRequest.Realm           = RPRealmUri;
            immediateRequest.ReturnTo        = RPUri;
            immediateRequest.LocalIdentifier = "http://somebody";
            var request = new AuthenticationRequest(provider, immediateRequest);

            // Now simulate the request being rejected and extract the user_setup_url
            request.IsAuthenticated = false;
            Uri userSetupUrl = ((NegativeAssertionResponse)await request.GetResponseAsync(CancellationToken.None)).UserSetupUrl;

            Assert.IsNotNull(userSetupUrl);

            // Now construct a new request as if it had just come in.
            var httpRequest  = new HttpRequestMessage(HttpMethod.Get, userSetupUrl);
            var setupRequest = (AuthenticationRequest)await provider.GetRequestAsync(httpRequest);

            var setupRequestMessage = (CheckIdRequest)setupRequest.RequestMessage;

            // And make sure all the right properties are set.
            Assert.IsFalse(setupRequestMessage.Immediate);
            Assert.AreEqual(immediateRequest.Realm, setupRequestMessage.Realm);
            Assert.AreEqual(immediateRequest.ReturnTo, setupRequestMessage.ReturnTo);
            Assert.AreEqual(immediateRequest.LocalIdentifier, setupRequestMessage.LocalIdentifier);
            Assert.AreEqual(immediateRequest.Version, setupRequestMessage.Version);
        }