oauth2

学习笔记:微服务13 spring boot2.x oauth2-client

末鹿安然 提交于 2019-12-06 17:50:24
前面oauth2 server设置好了,登录oauth2 server正常,但另外建一个oauth2 client 总是不能登录认证,网上说是spring boot 2 中去除了@EnableOAuth2Sso注解,今天终于找到适合我的spring boot 2.11的oauth2 client,实现了客户端认证。 1.新建spring start project 项目,我命名为microservice-oauth2-client-8805 2.pom.xml,上全文吧 <?xml version="1.0" encoding="UTF-8"?> <project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"> <modelVersion>4.0.0</modelVersion> <parent> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot

12-第三方登录

丶灬走出姿态 提交于 2019-12-06 14:12:21
一、第三方登录 1.1、第三方登录开发模式 首先注册第三方登录开发平台例如微博开放平台 1.2、oauth2.0获取微博的access_token apps/utils/weibo_longin.py def get_auth_url():#获取code参数 weibo_auth_url = 'https://api.weibo.com/oauth2/authorize' redirect_url = 'http://46.92.87.172.:8000/complete/weibo/' auth_url = weibo_auth_url+'?client_id={client_id}&redirect_uri={re_url}'.format(client_id=xxxxxxx,re_url=redirect_url) print(auth_url) def get_user_info(access_token='',uid=''): #根据微博API接口可以访问用户信息等 user_url = '' """ 可以利用这个接口爬取微博信息(爬虫思路) """ def get_access_token(code='xxxxxxxx'): #获取access_token参数 access_token_url = 'https://api.weibo.com/oauth2/access

微信公众号本地开发流程

邮差的信 提交于 2019-12-06 10:16:48
1.建立测试号 直接打开链接,微信扫码登录即可测试号管理页面 https://mp.weixin.qq.com/debug/cgi-bin/sandboxinfo?action=showinfo&t=sandbox/index ,如下图所示 2.在测试号中的【网 页授权 获取用户基本信息】中,设置回调地址IP( localhost,127.0.0.1均不能使用,请使用局域网IP或域名,测试 号回调地址支持域名和ip,正式公众号回调地址只支持域名。 ) 3.下载微信开发者工具,选择公众号网页开发 4.填写要测试的地址,修改 rediect_uri 回调地址, 访问腾讯服务器url规则如下: https://open.weixin.qq.com/connect/oauth2/authorize?appid= 你当前测试号的 appid &redirect_uri= 你的接口路径 ( 记得 uri 码 ) &response_type=code&scope=snsapi_userinfo#wechat_redirect 5.访问以上地址的话,微信服务器会转发到另一个地址,地址中包含code,可以通过code获取到用户的openId(openId是微信用户唯一凭证) 例如:http://www.baidu.com/spic&code

附录B OAuth2授权类型

纵饮孤独 提交于 2019-12-06 10:00:32
本附录主要内容 OAuth2密码授权(password grant) OAuth2客户端凭据授权(client credentials grant) OAuth2鉴权码授权(authorization code grant) OAuth2隐式授权(implicit grant) OAuth2令牌刷新 在阅读第7章时,读者可能会认为OAuth2看起来不太复杂。毕竟有一个验证服务,用于检查用户的凭据并颁发令牌给用户。每次用户想要调用由OAuth2服务器保护的服务时,都可以依次出示令牌。 遗憾的是,现实世界从来都不是简单的。由于Web应用程序和基于云的应用程序具有相互关联的性质,用户期望可以安全地共享自己的数据,并在不同服务所拥有的不同应用程序之间整合功能。这从安全角度来看,是一个独特的挑战,因为开发人员希望跨不同的应用程序进行整合,而不是强迫用户与他们想要集成的每个应用程序共享他们的凭据。 幸运的是,OAuth2是一个灵活的授权框架,它为应用程序提供了多种机制来对用户进行验证和授权,而不用强制他们共享凭据。但是,这也是OAuth2被认为是复杂的原因之一。这些验证机制被称为验证授权(authentication grant)。OAuth2有4种模式的验证授权,客户端应用程序可以使用它们来对用户进行验证、接收访问令牌,然后确认该令牌。这些授权分别是: 密码授权; 客户端凭据授权;

理解OAuth2

巧了我就是萌 提交于 2019-12-06 08:41:35
目录 理解OAuth2 Oatuh2用来做什么 Oauth2具体做法 Oauth2的流程 授权码模式 第三方引导用户跳转至认证服务器的授权页面 用户选择是否给予授权 认证服务器生成code并且让用户重定向至指定的url 第三方应用使用code到认证服务器处兑换令牌access token 认证服务器返回accesstoken 理解OAuth2 Oatuh2用来做什么 有这样一种场景,一个用户(假设是QQ),希望让一个第三方的应用(比如说某个论坛),能够得到关于自身的一些信息(唯一用户标识,比如说QQ号,用户个人信息,比如说是一些基础资料,昵称和头像等)。但是在获得这些资料的同时,却也不能提供用户名和密码之类的验证信息。比如说用户不可能将自身的用户名和密码给第三方让第三方到用户中心之类的地方去获取信息。要达到这样的结果肯定有许多的实现方式。而Oatuh2就是实现上述目标的一种规范,或者说是具体实现的指导方案。 Oauth2具体做法 首先来了解下Oatuh2中的几个名字,方便下文的阐述。 Third-party application : 第三方应用 Resource Owner : 资源持有者,一般就是用户自身 Authorization server : 认证服务器 Resource server : 资源服务器,即具体资源的存储方。与认证服务器是不同的逻辑节点,但是在物理上

微信 OAuth2.0 网页授权

爱⌒轻易说出口 提交于 2019-12-06 03:50:25
1、登录微信公众平台,在 "开发者中心" 找到 点击右侧的修改。 授权回调域名配置规范为全域名并且 不带http ,比如需要网页授权的域名为:www.qq.com,配置以后此域名下面的页面http://www.qq.com/music.html 、 http://www.qq.com/login.html 都可以进行OAuth2.0鉴权。但http://pay.qq.com 、 http://music.qq.com 、 http://qq.com无法进行OAuth2.0鉴权。 如:www.test.com 2、获取code 请求授权页面构造: $appid = "公众号在微信的appid"; $url = 'https://open.weixin.qq.com/connect/oauth2/authorize?appid='.$appid.'&redirect_uri=http://www. test .com/ oauth .php&response_type=code&scope=snsapi_userinfo&state=1#wechat_redirect'; header("Location:".$url); } 3、在域名根目录下,新建一个文件,命名为oauth.php(授权回调地址), <?php $appid = "公众号在微信的appid"; $secret =

JWT - Configuring a Authorization Server and setting the issuer as itself

我只是一个虾纸丫 提交于 2019-12-06 03:50:03
I am trying to set up an Authorization Server following this guide: http://bitoftech.net/2014/10/27/json-web-token-asp-net-web-api-2-jwt-owin-authorization-server/ However, I want to assign my local server (i.e. the server that the project runs on) as the issuer for CustomJwtFormatting . So, in Startup.cs I use: public void ConfigureOAuth(IAppBuilder app) { var issuer = HttpContext.Current.Request.Url.Scheme + System.Uri.SchemeDelimiter + HttpContext.Current.Request.Url.Host + (HttpContext.Current.Request.Url.IsDefaultPort ? "" : ":" + HttpContext.Current.Request.Url.Port); // get the host

PHP实现QQ第三方登录代码

我是研究僧i 提交于 2019-12-05 22:38:21
前言: PHP实现QQ快速登录,罗列了三种方法 方法一: 面向过程,回调地址和首次触发登录写到了一个方法页面【因为有了if做判断】, 方法二,三: 面向对象 1.先调用登录方法,向腾讯发送请求, 2.腾讯携带本网站唯一对应参数OPENID,ACCESSTOKEN,返回到对应回调页面, 3.回调页面接受到腾讯的参数后,通过这个两个参数,再发出对应的请求,如查询用户的数据。 4.腾讯做出对应的操作,如返回这个用户的数据给你 即使你没看懂,也没关系,按照我下面的流程来,保证你可以实现。 前期准备: 使用人家腾讯的功能,总得和人家打招呼吧! QQ互联首页:http://connect.qq.com/ 进入网址后,按如下操作来: 一.进入官网 二.申请创建【网站】应用 三.按要求填写资料 注意网站地址:填写你要设置快速登录的网址,eg:http://www.test.com; 回调地址:填写你发送QQ快速登陆后,腾讯得给你信息,这个信息往此页面接受。eg:http://www.test.com/accept_info.php 【详细的申请填写,请见官方提示,这里不做赘述】 四.申请成功后,完善信息 最终要求,获得APP_ID ,APP_KEY 五.代码部分: 在你对应的PHP文件内写入,如下 方法一, 面向过程法 使用方法:配置$app_id,$app_secret,$my_url后

OAuth2 Password grant with node js

血红的双手。 提交于 2019-12-05 16:26:07
I am designing a web application that is mainly divided into following two parts Web site (UI) : Node JS Express application will be hosted as www.mysite.com Rest API: Business logic(Atuhentiation, Authorization, business logic) and will be hosted as some different domain for example api.mysite.com I want to implement the OAuth2 for this application. I read through OAuth2 and understood it's various flows and based on my understanding, I concluded that " Resource Owner Password Credentials " flow is a way to go as Client and Service both belongs to me and user will also directly register with

Reddit API returns HTTP 403

夙愿已清 提交于 2019-12-05 13:08:15
Following the OAuth2 login flow described at https://github.com/reddit/reddit/wiki/OAuth2 I got to the point where POST-ing to https://www.reddit.com/api/v1/access_token returns something like this: {'token_type': 'bearer', 'expires_in': 3600, 'scope': 'identity', 'access_token': '*****'} Then I do GET https://oauth.reddit.com/api/v1/me With this header: Authorization: bearer ***** The response is HTTP 403 Unauthorized. But why? It is clear that the access token has 'identity' scope. It is also documented that the /api/v1/me call requires this scope only. (See https://www.reddit.com/dev/api