【Android Training - UserInfo】记住登入用户的信息[Lesson 2 - 使用OAuth2来进行身份鉴定]

Authenticating to OAuth2 Services [使用OAuth2来进行鉴定]

  • 为了安全的访问线上服务,用户需要在service上进行鉴定,他们需要提供身份的证明。对于一个程序来说,如果是访问第三方的服务,那么这个安全问题就更加复杂。【比如,你有个资料在A服务器上,但是你需要在B上面对A里面的数据进行操作,这个时候如果把登入A的帐号与密码给B去直接操作就不够安全,简单的方法是先把A上的资料拿下来,再弄到B上面去,然后B再做操作,这又显得很不方便,就是为了解决这样类似的问题,才诞生了OAuth。关于OAuth2的详情,请参考:http://oauth.net/2/,谢谢!
  • 目前行业内解决这种第三方服务身份鉴定的方法是使用OAuth2协议。OAuth2提供了auth token,它代表用户身份与用户对于程序的授权。这一课演示了如何使用OAuth2连接到Google Server。同样在其他支持OAuth2协议的服务上都可以使用类似的方法。
  • 使用OAuth2有利于:
    • 从用户那得到授权,使用账户信息来访问online service。
    • 对online service进行鉴定,保护用户利益。
    • 处理认证错误。

Gather Information[收集信息]

  • 在开始使用OAuth2之前,你需要获取到下面一些信息:
    • 你想访问的服务地址。
    • auth scope,app获取到用来表示操作的权限范围的字串。例如,Google Tasks的read-only的auth scope是View your tasks,但是read-write的auth scope是Manage Your
  • 1
    点赞
  • 4
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
`spring-boot-starter-oauth2-authorization-server`是Spring Boot提供的OAuth2认证服务器的Starter,可以用于构建安全的OAuth2认证授权服务器。 以下是使用`spring-boot-starter-oauth2-authorization-server`构建OAuth2认证服务器的简单步骤: 1. 添加依赖 在`pom.xml`文件中添加以下依赖: ``` <dependency> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter-oauth2-authorization-server</artifactId> </dependency> ``` 2. 配置认证服务器 在`application.yml`文件中添加以下配置: ``` spring: security: oauth2: authorization: server: jwt: signing-key: mySecretKey client: registration: my-client: client-id: my-client client-secret: mySecret scope: - read - write redirect-uri-template: http://localhost:8080/login/oauth2/code/my-client authorization-grant-type: authorization_code client-name: My Client provider: my-authorization-server: authorization-uri: http://localhost:8080/oauth2/authorize token-uri: http://localhost:8080/oauth2/token user-info-uri: http://localhost:8080/oauth2/userinfo user-name-attribute: name ``` 其中,`jwt.signing-key`是用于签名JWT的密钥,`client.registration`用于配置客户端信息,`client.provider`用于配置认证服务器信息。 3. 启动认证服务器 在Spring Boot应用程序中添加`@EnableAuthorizationServer`注解,启动OAuth2认证服务器: ```java @SpringBootApplication @EnableAuthorizationServer public class OAuth2AuthorizationServerApplication { public static void main(String[] args) { SpringApplication.run(OAuth2AuthorizationServerApplication.class, args); } } ``` 以上就是使用`spring-boot-starter-oauth2-authorization-server`构建OAuth2认证服务器的简单步骤。

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值