예제 #1
0
        public async Task ReturnResponse(IOwinContext context, IIdentityServerRecaptchaOptions options)
        {
            var identityServerChallengeResource = new IdentityServerBadRequestChallengeResource
            {
                Message       = CreateResponseMessage(),
                ChallengeHtml = _recaptchaPage.CreateHtmlBody()
            };

            await context.ReturnResponse(HttpStatusCode.BadRequest, identityServerChallengeResource);
        }
예제 #2
0
 public async Task ReturnResponse(IOwinContext context, IIdentityServerRecaptchaOptions options)
 {
     await context.ReturnResponse(HttpStatusCode.Unauthorized,
                                  new IdentityServerUnauthorizedChallengeResource
     {
         ChallengeHtml   = _recaptchaPage.CreateHtmlBody(),
         LinkToChallenge = options.LinkToChallenge,
         Description     = CreateResponseMessage()
     }, $@"recaptcha url=""{options.LinkToChallenge}""");
 }
        public static bool SupportsPartialRecaptcha(this IIdentityServerRecaptchaOptions openIdConnectRequestOptions, IOpenIdConnectRequest openIdConnectRequest)
        {
            var basicAuthenticationHeaderValue = openIdConnectRequest.GetBasicAuthenticationHeaderValue();

            if (string.IsNullOrEmpty(basicAuthenticationHeaderValue))
            {
                return(true);
            }

            var basicAuthenticationHeaders = openIdConnectRequestOptions.WebClients.Select(client => Convert.ToBase64String(Encoding.UTF8.GetBytes($"{client.ClientId}:{client.Secret}")))
                                             .Select(authorizationValue => new AuthenticationHeaderValue("Basic", authorizationValue));

            return(basicAuthenticationHeaders
                   .Any(authenticationHeaderValue =>
            {
                return authenticationHeaderValue.ToString() == basicAuthenticationHeaderValue;
            }));
        }
        private static void UseRequestedChallengeType(this IAppBuilder app, IIdentityServerRecaptchaOptions options)
        {
            switch (options.HttpChallengeStatusCode)
            {
            case HttpStatusCode.OK:
                app.UsePerOwinContext <IHttpRecaptchaChallenge>(
                    () => new HttpRecaptchaOkChallenge(new RecaptchaPage(options)));
                break;

            case HttpStatusCode.Unauthorized:
                app.UsePerOwinContext <IHttpRecaptchaChallenge>(
                    () => new HttpRecaptchaUnauthorizedChallenge(new RecaptchaPage(options)));
                break;

            default:
                app.UsePerOwinContext <IHttpRecaptchaChallenge>(
                    () => new HttpRecaptchaBadRequestChallenge(new RecaptchaPage(options)));
                break;
            }
        }
예제 #5
0
 public RecaptchaPage(IIdentityServerRecaptchaOptions options)
 {
     _options = options;
 }