Secure REST API and Mobile(1)Document Read and Understand OAUTH2

本文详细介绍了OAuth2的授权流程及应用场景,对比了OAuth1与OAuth2的不同之处,并列举了多个知名服务提供商如Facebook、Google等所采用的具体授权类型。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

Secure REST API and Mobile(1)Document Read and Understand OAUTH2

I used to use OAuth1 before, but it seems that it is different from OAuth2.

1. Introduction on OAuth2
Resource Owner — User
Client — App
Authorization Server
Resource Server — API

Client should be registered first.
Client Registration
Client ID
Client Secret
Redirect URI

Public V.S. Confidential Client
Confidential - Server-side Application, send Client ID+Secret to Auth.Server
Public - Moible App/ JavaScript App

Endpoints
Authorization Endpoint — User authorize — Web Page — Grant — 302 to Client Redirect URI
Token Endpoint — Client fetch the token - JSON API - fetch the Token with Grant
Redirection Endpoint — Client receive the info

SSL, Auth.Server endpoints must be HTTPS, Client Redirection Endpoint is not.

Resource Server
Client use Token to fetch the info from Resource Server - Password-Free API

There are several flows (Taobao Top as example)
user ——— browser ———— ———— app ————— TOP
get app URL ——————>
<——— send 302 to Oauth
GET /authorize — — ——————————>
Logon and Grant —————————————————————>
<— —————— ——— redirect to redirect_URI
get redirect URI ————>
POST token————>
<—— — Access Token


2. Public Clients - Implicit Grant Flow
only for public client, Android App, iOS App, Javascript App.
Grant will not be transferred to Client, directly give Token
No Token Endpoint
Token has short lifetime
No Refresh Token

OAuth2 Provider
Facebook — Auth Code, Implicit, Client Cred.
Github — Auth Code, Password
Twitter — Client Cred.
Google — Auth Code, Implicit
Microsoft — Auth Code, Implicit
Dropbox — Auth Code, Implicit
Amazon — Auth Code, Implicit
Bitly — Auth Code, Password
Sina weibo — Auth Code
Douban — Auth Code, Implicit
BOX — Auth Code
Basecamp — Auth Code

3. Try to secure our API
It seems to me that we need to use other provide for authentication, we need to do the authorization ourselves.

Next step I will investigate PHP codes from our company, hello.js and some customized projects.
http://adodson.com/hello.js/

https://github.com/tcompiegne/oauth2-resource-server-samples
https://github.com/tcompiegne/oauth2-server
https://github.com/tcompiegne/oauth2-client-samples

References:
OAuth
http://sillycat.iteye.com/blog/1265917 protocol and the example
http://sillycat.iteye.com/blog/1265918 sample provider
http://sillycat.iteye.com/blog/1265922 sample provider
http://sillycat.iteye.com/blog/1265923 all about the protocol

OAuth2
http://oauth.net/2/

http://www.ruanyifeng.com/blog/2014/05/oauth_2_0.html

Very good MIT Library
https://github.com/MrSwitch/hello.js
http://adodson.com/hello.js/

http://security.stackexchange.com/questions/67343/secure-rest-api-and-single-page-app-by-using-external-oauth-2-authorization-code

example
https://github.com/jcleblanc/oauth

OpenId
http://sillycat.iteye.com/blog/1004721
http://sillycat.iteye.com/blog/1004723
http://sillycat.iteye.com/blog/1543234
http://sillycat.iteye.com/blog/1543929
http://sillycat.iteye.com/blog/1543974

oauth provider
https://oauth.io/providers

powerful OAUTH2 client
http://adodson.com/hello.js/

OAUTH2 providers
https://github.com/tcompiegne/oauth2-resource-server-samples
https://github.com/tcompiegne/oauth2-server
https://github.com/tcompiegne/oauth2-client-samples
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值