开放认证协议OAuth -- 协议工作流程

Email:biansutao[AT]gmail[DOT]com

OAuth协议致力于使网站和应用程序(统称为消费方)能够在无须用户透露其认证证书的情况下,通过API访问某个web服务(统称为服务提供方)的受保护资源。更一般地说,OAuth为API认证提供了一个可自由实现且通用的方法。

一个典型的例子是某打印服务提供商printer.example.com(消费方),希望在无须用户提供其照片存储站点密码的情况下,访问用户储存在photos.example.net(服务提供方)上的个人照片。

OAuth不强求一个特定的用户接口或操作模式,也不限定服务提供方如何验证用户,特别适合认证证书对消费方不可用的情况,例如OpenID。

OAuth致力于为托管web服务认证提供统一的体验和实现,形成一个社区驱动的协议。OAuth构建于已被多个站点独立实现的已有协议和最佳化实践之上,是一个被大小服务提供者所支持、并为应用开发者和用户增进持续性和可信度的开放标准。

  

OAuth is best explained with real-life examples. The specification  includes in Appendix A a similar example but focuses on the HTTP calls  syntax. This walk-through demonstrates a typical OAuth session and  includes the perspectives of the User, Consumer, and Service Provider.  The websites and people mentioned are fictional. The Scottish references  are real. And so our story begins…

OAuth最好使用真实生活中的例子来进行解释。OAuth规范的附录A中有一个与此 相似的例子,但是它更关注HTTP调用的过程。这个例子在OAuth会话中是有代表性的,它包括了用户,消费者,服务提供者。这个例子中提到的人和网站都 是虚构出来的不是真实的。关于苏格兰的引用是真实的。好了,让我们开始我们的故事吧。

  

Flow Step 1

Jane is back from her Scotland vacation.  She spent 2 weeks on the island of Islay sampling Scotch. When she gets  back home, Jane wants to share some of her vacation photos with her  friends. Jane uses Faji, a photo sharing site, for sharing journey  photos. She signs into her faji.com account, and uploads two photos  which she marks private.

Jane刚刚从苏格兰度假中回来。她在这个岛上带了两周。当她回到家中的时候,她想和她的朋友们分享一下她度假过程中照的照片。Jane使用Faji,一个图片共享网站,来分享她旅途中的照片。她登录进她的faji账户,并且上传了两张她标记为私有的照片。

Using OAuth terminology, Jane is the User and Faji the Service Provider. The 2 photos Jane uploaded are the Protected Resources.

使用OAuth的术语来描述一下,Jane是用户,Faji是服务提供者,Jane上传的两张照片是受保护的资源。

Flow Screen 1

After sharing her photos with a few of her  online friends, Jane wants to also share them with her grandmother. She  doesn’t want to share her rare bottle of Scotch with anyone. But grandma  doesn’t have an internet connection so Jane plans to order prints and  have them mailed to grandma. Being a responsible person, Jane uses  Beppa, an environmentally friendly photo printing service.

在和她几个在线 的朋友分享过照片之后,Jane也想要把她的照片分享给她的外祖母。她不想要与任何人分享她在苏格兰度假过程中弄到的一瓶罕见的威士忌。但是外祖母不会上 网所以Jane去把照片打印出来寄给她的外祖母。作为一个认真负责的人,Jane使用Beppa,一个周围的友好的图片打印服务。

Using OAuth terminology, Beppa is the Consumer. Since Jane marked the  photos as private, Beppa must use OAuth to gain access to the photos in  order to print them.

使用OAuth术语来描述一下,Beppa是消费者,自从Jane把她的照片标记为私有以后,Beppa必须使用OAuth来获取对这些私有图片的访问权以便把他们打印出来。

Jane visits beppa.com and begins to order  prints. Beppa supports importing images from many photo sharing sites,  including Faji. Jane selects the photos source and clicks Continue.

Jane访问beppa.com开始下单打印。Beppa支持从许多图片分享网站导入图片,包括Faji。Jane选择了图片来源并点击继续。

Flow Screen 2

When Beppa added support for Faji photo import, a Beppa developer  known in OAuth as a Consumer Developer obtained a Consumer Key and  Consumer Secret from Faji to be used with Faji’s OAuth-enabled API.

当Beppa添加支持从Faji导入图片的时候,一个Beppa开发者知道在OAuth中作为一个消费方开发者要从Faji获取消费Key和消费密钥以便使用Faji提供的OAuth认证API。

After Jane clicks Continue, something important happens in the  background between Beppa and Faji. Beppa requests from Faji a Request  Token. At this point, the Request Token is not User-specific, and can be  used by Beppa to gain User approval from Jane to access her private  photos.

当 Jane点击了继续以后,一些重要的事情在Beppa和Faji之间发生了。Beppa从Faji请求了一个Request Token。用户对这个Request Token是不了解的,这个Request Token可以被Beppa来使用获取Jane的审批用来获取她的私有图片资源。

Flow Step 2

Jane clicked Continue and is now waiting  for her screen to change. She sips from her prized Black Bowmore while  waiting for the next page to load.

Jane点击继续并等待她的电脑屏幕改变。她啜饮了一小口她度假获得的奖品

黑鲍莫尔威士忌,在等待下一个页面加载的空闲时间。

When Beppa receives the Request Token, it redirects Jane to the Faji  OAuth User Authorization URL with the Request Token and asks Faji to  redirect Jane back once approval has been granted to  http://beppa.com/order.

当Beppa接受到Request Token以后,Beppa拿着接收到的Request Token重定向Jane到Faji的OAuth用户授权URL并且要求Faji在完成用户授权以后重定向Jane到Http://beppa.com/order。

Jane has been redirected to Faji and is requested to sign into the  site. OAuth requires that Service Providers first authenticate the User,  and then ask them to grant access to the Consumer.

Jane被重定向到Faji并且被要求登录。OAuth要求服务提供者首先认证用户,认证完成之后要求用户批准消费者的访问。

Jane notices she is now at a Faji page by looking at the browser URL, and enters her username and password.
Jane注意到浏览器的URL地址到达了Faji的页面,并要求她填入用户名和密码。

Flow Screen 3

OAuth allows Jane to keep her username and password private and not  share them with Beppa or any other site. At no time does Jane enters her  credentials into beppa.com.

OAuth允许Jane保护她的用户和密码可以不分享给Beppa或任何其他的网站。Jane可以选择不输入她的用户名和密码进入beppa.com网站。

After successfully logging into Faji, Jane is asked to grant access  to Beppa, the Consumer. Faji informs Jane of who is requesting access  (in this case Beppa) and the type of access being granted. Jane can  approve or deny access.

成功登录进Faji以后,Jane被要求授权给Beppa这个消费者。Faji提醒Jane谁正在请求访问(在这里是Beppa)和需要授权访问的内容。Jane可以审批通过也可以拒绝这个访问。

Jane makes sure Beppa is getting the  limited access it needs. She does not want to allow Beppa to change her  photos or do anything else to them. She also notes this is a onetime  access good for one hour which should be enough time for Beppa to fetch  her photos.

Jane确保Beppa正在获取的是她所需要的有限的访问。她不想允许Beppa更改她的图片或对她的图片做任何其他的操作。她也注意到了这是一个一小时的访问这些时间足够Beppa来获取她的图片了。

Flow Screen 4

Once Jane approves the request, Faji marks the Request Token as  User-authorized by Jane. Jane’s browser is redirected back to Beppa, to  the URL previously provided http://beppa.com/order together with the  Request Token. This allows Beppa to know it can now continue to fetch  Jane’s photos.

一旦Jane审批通过了这个请求,Faji标记这个Request Token被Jane授权了。Jane的浏览器被重定向回到了Beppa,以前提供的URLhttp://beppa.com/order现在带有了 Request Token。现在允许Beppa获取Jane的图片了,它可以继续执行它的打印操作了。

Jane waits for Beppa to present her with her photos fetched from her Faji account.

Jane等待Beppa代表她从Faji获取她的图片。

Flow Screen 5

While Jane waits, Beppa uses the authorized Request Token and  exchanges it for an Access Token. Request Tokens are only good for  obtaining User approval, while Access Tokens are used to access  Protected Resources, in this case Jane’s photos. In the first request,  Beppa exchanges the Request Token for an Access Token and in the second  (can be multiple requests, one for a list of photos, and a few more to  get each photo) request gets the photos.

当Jane等待的时候,Beppa使用这个授权的Request Token从Faji那里交换了一个Access Token。

Request Token用来获取用户的审批,而Access Token是被用来获取受保护的资源的,在这里指的是Jane的图片。在第一个请求中,Beppa拿Request Token换取了一个Access Token,在第二个请求(可以是多个请求,每一个都获取若干个图片)中来得到图片。

Flow Step 3

When Beppa is done, Jane’s browser refreshes to complete the order.

Beppa successfully fetched Jane’s photo. They are presented as thumbnails for her to pick and place her order.

当Bepa完成的时候,jane的浏览器重新刷新来完成这次下单。

Beppa成功的获取了Jane的图片。Beppa获取了图片并处理成了缩略图下单完成了。

Jane is very impressed how Beppa grabbed  her photos without asking for her username and password. She likes what  she sees and place the print order.

Jane对于Beppa获取她的图片而没有要求她的用户名和密码的情况印象深刻。她喜欢她所看到的,她成功的打印了她的图片。

Flow Screen 6

【本文由phoenix_bian 授权译言网呈现,如需转载请与phoenix_bian联系】

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值