/// <summary>
        /// Creates a query string using the using the current contents of this <see cref="OpenIdConnectMessage"/>.
        /// </summary>
        /// <returns>The uri to use for a redirect.</returns>
        public string CreateLogoutRequestUrl()
        {
            OpenIdConnectMessage openIdConnectMessage = Clone();

            openIdConnectMessage.RequestType = OpenIdConnectRequestType.LogoutRequest;
            return(openIdConnectMessage.BuildRedirectUrl());
        }
        /// <summary>
        /// Creates an OpenIdConnect message using the current contents of this <see cref="OpenIdConnectMessage"/>.
        /// </summary>
        /// <returns>The uri to use for a redirect.</returns>
        public string CreateAuthenticationRequestUrl()
        {
            OpenIdConnectMessage openIdConnectMessage = Clone();

            openIdConnectMessage.RequestType = OpenIdConnectRequestType.AuthenticationRequest;
            return(openIdConnectMessage.BuildRedirectUrl());
        }
        public void OpenIdConnectMessage_IssuerAddressHasQuery()
        {
            List<string> errors = new List<string>();
            var address = "http://gotJwt.onmicrosoft.com/?foo=bar";
            var clientId = Guid.NewGuid().ToString();
            var message = new OpenIdConnectMessage(address);

            var url = message.BuildRedirectUrl();
            Report("1", errors, url, address);

            message.ClientId = clientId;
            url = message.BuildRedirectUrl();
            var expected = string.Format(CultureInfo.InvariantCulture, @"{0}&client_id={1}", address, clientId);

            Report("2", errors, url, expected);
        }
        public void OpenIdConnectMessage_Publics()
        {
            string issuerAddress = "http://gotJwt.onmicrosoft.com";
            string customParameterName = "Custom Parameter Name";
            string customParameterValue = "Custom Parameter Value";
            string nonce = Guid.NewGuid().ToString();
            string redirectUri = "http://gotJwt.onmicrosoft.com/signedIn";
            string resource = "location data";

            List<string> errors = new List<string>();

            // Empty string
            OpenIdConnectMessage message = new OpenIdConnectMessage();

            string url = message.BuildRedirectUrl();
            string expected = string.Format(CultureInfo.InvariantCulture, @"");
            Report("1", errors, url, expected);

            message.ResponseMode = OpenIdConnectResponseModes.FormPost;
            message.ResponseType = OpenIdConnectResponseTypes.CodeIdToken;
            message.Scope = OpenIdConnectScopes.OpenIdProfile;

            url = message.BuildRedirectUrl();
            expected = string.Format(CultureInfo.InvariantCulture, @"?response_mode=form_post&response_type=code+id_token&scope=openid+profile");
            Report("1a", errors, url, expected);

            // Nonce added
            message.Nonce = nonce;
            url = message.BuildRedirectUrl();
            expected = string.Format(CultureInfo.InvariantCulture, @"?response_mode=form_post&response_type=code+id_token&scope=openid+profile&nonce={0}", nonce);
            Report("2", errors, url, expected);

            // IssuerAddress only
            message = new OpenIdConnectMessage(issuerAddress);
            message.ResponseMode = OpenIdConnectResponseModes.FormPost;
            message.ResponseType = OpenIdConnectResponseTypes.CodeIdToken;
            message.Scope = OpenIdConnectScopes.OpenIdProfile;
            message.Nonce = nonce;

            url = message.BuildRedirectUrl();
            expected = string.Format(CultureInfo.InvariantCulture, @"{0}?response_mode=form_post&response_type=code+id_token&scope=openid+profile&nonce={1}", issuerAddress, nonce);
            Report("3", errors, url, expected);

            // IssuerAdderss and Redirect_uri
            message.RedirectUri = redirectUri;
            url = message.BuildRedirectUrl();
            expected = string.Format(CultureInfo.InvariantCulture, @"{0}?response_mode=form_post&response_type=code+id_token&scope=openid+profile&nonce={1}&redirect_uri={2}", issuerAddress, message.Nonce, HttpUtility.UrlEncode(redirectUri));
            Report("4", errors, url, expected);

            // IssuerAdderss empty and Redirect_uri
            message.IssuerAddress = string.Empty;
            url = message.BuildRedirectUrl();
            expected = string.Format(CultureInfo.InvariantCulture, @"?response_mode=form_post&response_type=code+id_token&scope=openid+profile&nonce={0}&redirect_uri={1}", message.Nonce, HttpUtility.UrlEncode(redirectUri));
            Report("5", errors, url, expected);

            // IssuerAdderss, Redirect_uri, Response
            message = new OpenIdConnectMessage(issuerAddress);
            message.ResponseMode = OpenIdConnectResponseModes.FormPost;
            message.ResponseType = OpenIdConnectResponseTypes.CodeIdToken;
            message.Scope = OpenIdConnectScopes.OpenIdProfile;
            message.Nonce = nonce;
            message.RedirectUri = redirectUri;
            message.Resource = resource;
            url = message.BuildRedirectUrl();
            expected = string.Format(CultureInfo.InvariantCulture, @"{0}?response_mode=form_post&response_type=code+id_token&scope=openid+profile&nonce={1}&redirect_uri={2}&resource={3}", issuerAddress, message.Nonce, HttpUtility.UrlEncode(redirectUri), HttpUtility.UrlEncode(resource));
            Report("6", errors, url, expected);

            // IssuerAdderss, Redirect_uri, Response, customParam
            message = new OpenIdConnectMessage(issuerAddress);
            message.ResponseMode = OpenIdConnectResponseModes.FormPost;
            message.ResponseType = OpenIdConnectResponseTypes.CodeIdToken;
            message.Scope = OpenIdConnectScopes.OpenIdProfile;
            message.Nonce = nonce;
            message.Parameters.Add(customParameterName, customParameterValue);
            message.RedirectUri = redirectUri;
            message.Resource = resource;
            url = message.BuildRedirectUrl();
            expected = string.Format(CultureInfo.InvariantCulture, @"{0}?response_mode=form_post&response_type=code+id_token&scope=openid+profile&nonce={1}&{2}={3}&redirect_uri={4}&resource={5}", issuerAddress, message.Nonce, HttpUtility.UrlEncode(customParameterName), HttpUtility.UrlEncode(customParameterValue), HttpUtility.UrlEncode(redirectUri), HttpUtility.UrlEncode(resource));
            Report("7", errors, url, expected);

            if (errors.Count != 0)
            {
                StringBuilder sb = new StringBuilder();
                sb.AppendLine(Environment.NewLine);
                foreach (string str in errors)
                    sb.AppendLine(str);

                Assert.Fail(sb.ToString());
            }
        }