public CommandResult Run(HttpRequestData request, IOptions options, HttpSessionState session)
 {
     return new CommandResult()
     {
         HttpStatusCode = HttpStatusCode.NotFound
     };
 }
        public CommandResult Run(HttpRequestData request, IOptions options, HttpSessionState session)
        {
            if (request == null)
            {
                throw new ArgumentNullException(nameof(request));
            }

            if (options == null)
            {
                throw new ArgumentNullException(nameof(options));
            }

            var urls = new OpenIDUrls(options.RPOptions, request.ApplicationUrl);

            OIDCAuthCodeResponseMessage authResponse = GetAuthResponse(request, session);
            OIDCTokenResponseMessage tokenResponse = GetToken(authResponse, options, session, urls.CodeCallbackCommand.ToString());

            OIDCUserInfoRequestMessage userInfoRequestMessage = new OIDCUserInfoRequestMessage();
            OIDCUserInfoResponseMessage userInfoResponse = GetUserInfo(authResponse, options, session, tokenResponse.AccessToken);

            var principal = GetPrincipal(userInfoResponse, options, session);
            string ReturnUrl = request.QueryString["ReturnUrl"].FirstOrDefault()?? urls.ApplicationBase.ToString();

            return new CommandResult()
            {
                HttpStatusCode = HttpStatusCode.SeeOther,
                Location = new Uri(ReturnUrl),
                Principal = principal
            };
        }
        public CommandResult Run(HttpRequestData request, IOptions options, HttpSessionState session)
        {
            if (request == null)
            {
                throw new ArgumentNullException(nameof(request));
            }

            if (options == null)
            {
                throw new ArgumentNullException(nameof(options));
            }

            string rpEntityId = request.QueryString["rp"].FirstOrDefault().Replace('+', ' ');
            var providerData = options.OpenIDProviders[rpEntityId];
            var urls = new OpenIDUrls(options.RPOptions, request.ApplicationUrl);
            providerData.RegisterClient(options.RPOptions, urls);

            OIDCAuthorizationRequestMessage requestMessage = generateRequestMessage(providerData, urls);
            string requestObject = null;

            if (providerData.Sign && options.RPOptions.SignCertificate != null)
            {
                OIDCAuthorizationRequestMessage rObject = generateRequestObject(providerData, urls, requestMessage.State, requestMessage.Nonce);
                requestObject = JWT.Encode(rObject.SerializeToJsonString(), getCertificateKey(options.RPOptions.SignCertificate), JwsAlgorithm.RS256);
                requestMessage.Request = requestObject;
            }

            if (providerData.Encrypt && options.RPOptions.EncCertificate != null)
            {
                if (requestObject == null)
                {
                    OIDCAuthorizationRequestMessage rObject = generateRequestObject(providerData, urls, requestMessage.State, requestMessage.Nonce);
                    requestObject = rObject.SerializeToJsonString();
                }

                requestObject = JWT.Encode(requestObject, getCertificateKey(options.RPOptions.EncCertificate), JweAlgorithm.RSA1_5, JweEncryption.A128CBC_HS256);
                requestMessage.Request = requestObject;
            }

            session.Add("op", rpEntityId);
            session.Add("nonce", requestMessage.Nonce);
            session.Add("state", requestMessage.State);

            return new CommandResult()
            {
                HttpStatusCode = HttpStatusCode.SeeOther,
                Location = new Uri(providerData.ProviderMatadata.AuthorizationEndpoint + "?" + requestMessage.SerializeToQueryString())
            };
        }
        public CommandResult Run(HttpRequestData request, IOptions options, HttpSessionState session)
        {
            if (request == null)
            {
                throw new ArgumentNullException(nameof(request));
            }

            if (options == null)
            {
                throw new ArgumentNullException(nameof(options));
            }

            Dictionary<string, object> keysDict = KeyManager.GetKeysJwkDict(options.RPOptions.SignCertificate, options.RPOptions.EncCertificate);
            string body = Serializer.SerializeToJson(keysDict);

            return new CommandResult()
            {
                HttpStatusCode = HttpStatusCode.OK,
                Content = body
            };
        }
 private OIDCAuthCodeResponseMessage GetAuthResponse(HttpRequestData request, HttpSessionState session)
 {
     var scope = new List<MessageScope>() { MessageScope.Openid, MessageScope.Profile };
     var state = session["state"];
     return rp.ParseAuthCodeResponse(request.Url.Query, scope);
 }