# longpoll **Repository Path**: youngboyvip/longpoll ## Basic Information - **Project Name**: longpoll - **Description**: Java长轮巡模拟扫码登录 - **Primary Language**: Java - **License**: Not specified - **Default Branch**: master - **Homepage**: None - **GVP Project**: No ## Statistics - **Stars**: 1 - **Forks**: 0 - **Created**: 2019-04-11 - **Last Updated**: 2022-07-15 ## Categories & Tags **Categories**: Uncategorized **Tags**: None ## README # Java Http长轮巡模拟扫码登录 ## 实现原理 使用Servlet3异步接口实现非阻塞长连接接口, 异步上下文对象使用 `ScheduledExecutorService` 线程池定时调度 事件总线使用了 `guava` 中的 `EventBus` 实现 ## curl 执行顺序 ``` //发起长链接请求 curl -X GET \ 'http://localhost:8080/api/longPolling?uuid=666&type=scan' \ -H 'Cache-Control: no-cache' \ -H 'Postman-Token: 531c77a6-d6b1-4cb5-b666-de1908123660' //用户扫码,长连接响应用户扫码状态信息 curl -X GET \ http://localhost:8080/api/scan/666 \ -H 'Cache-Control: no-cache' \ -H 'Postman-Token: d06921c5-b063-49f3-88cc-bb32de148000' //扫码时候继续发起长连接等待用户确认授权 curl -X GET \ 'http://localhost:8080/api/longPolling?uuid=666&type=confirm' \ -H 'Cache-Control: no-cache' \ -H 'Postman-Token: 5aab47be-8522-4f97-96a5-d5dba035b4e7' //用户确认授权,长连接请求返回token curl -X GET \ 'http://localhost:8080/api/confirm/666?result=success' \ -H 'Cache-Control: no-cache' \ -H 'Postman-Token: 6855c644-23d5-4bbb-87f3-e6b344a70665' ``` ## OAuth2授权码模式 关键类 DefaultLoginPageGeneratingFilter 生成登录页面的过滤器 OAuth2AuthenticationProcessingFilter OAuth2 认证过滤器 OAuth2ClientAuthenticationProcessingFilter 从认证服务器请求OAuth2授权token,并添加到SecurityContext SsoSecurityConfigurer OAuth2ClientContextFilter 此类处理上下文的异常,如果是UserRedirectRequiredException会重定向到指定登录页面 DefaultLoginPageConfigurer 注册了DefaultLoginPageGeneratingFilter 未生效的过滤器列表 ![unnormal](./img/unnormal.png) 正常的过滤列表 ![normal](./img/nomal.png) ## 二维码怎么生成? uuid 怎么生成? ## OAuth2 + OpenId 仿微信公众平台扫码登录 开发中... 参与讨论 访问 [https://youngboy.vip](https://youngboy.vip) q群:611515822