Skip to Content
JavaScript 经典实例:第三版
book

JavaScript 经典实例:第三版

by Adam D. Scott, Matthew MacDonald, Shelley Powers
September 2022
Intermediate to advanced
585 pages
8h 17m
Chinese
China Electric Power Press Ltd.
Content preview from JavaScript 经典实例:第三版
使用
Express
构建
Web
应用
541
上述示例匹配所有以
day
结尾的请求。例如,在本地开发环境中请求
http://
localhost:3000/Sunday
,页面中显示的结果为“
Every day feels like Sunday
”。
21.4
使用
OAuth
21.4.1
问题
你想在
Node
应用中访问第三方
API
(例如
GitHub
Facebook
Twitter
),但是需
要授权。具体而言,需要
OAuth
授权。
21.4.2
方案
你需要在应用中使用
OAuth
客户端,还需要满足资源提供方对
OAuth
提出的要求。
详见下一节的讨论。
21.4.3
讨论
OAuth
是一个授权框架,多数流行的社交媒体和云内容应用都使用它。如果你访问
过的网站曾经要求你授权从第三方服务(例如
GitHub
)中获取数据,那么你就参与
OAuth
授权流程。
OAuth
有两个版本,
1.0
2.0
,二者互不兼容。
OAuth 1.0
基于
Flickr
Google
发的专有
API
,关注的重点是网页,无法顺利跨越
Web
、移动设备和服务应用之间
的屏障。如果想在移动应用中访问资源,用户要在移动浏览器中登录应用,把访问
令牌复制到应用中。
OAuth 1.0
受人诟病的另一点是,要求授权服务器与资源服务
器相同,这在与服务提供方(例如
Twitter
Facebook
Amazon
)交互时就显得不
便了。
OAuth 2.0
的授权过程较简单,而且为不同的情况提供了不同的授权方式(流程)。
不过,有些人会说,这样做牺牲了安全性,因为对加密散列令牌和请求字符串的要 ...
Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.

Read now

Unlock full access

More than 5,000 organizations count on O’Reilly

AirBnbBlueOriginElectronic ArtsHomeDepotNasdaqRakutenTata Consultancy Services

QuotationMarkO’Reilly covers everything we've got, with content to help us build a world-class technology community, upgrade the capabilities and competencies of our teams, and improve overall team performance as well as their engagement.
Julian F.
Head of Cybersecurity
QuotationMarkI wanted to learn C and C++, but it didn't click for me until I picked up an O'Reilly book. When I went on the O’Reilly platform, I was astonished to find all the books there, plus live events and sandboxes so you could play around with the technology.
Addison B.
Field Engineer
QuotationMarkI’ve been on the O’Reilly platform for more than eight years. I use a couple of learning platforms, but I'm on O'Reilly more than anybody else. When you're there, you start learning. I'm never disappointed.
Amir M.
Data Platform Tech Lead
QuotationMarkI'm always learning. So when I got on to O'Reilly, I was like a kid in a candy store. There are playlists. There are answers. There's on-demand training. It's worth its weight in gold, in terms of what it allows me to do.
Mark W.
Embedded Software Engineer

You might also like

JavaScript Patterns

JavaScript Patterns

Stoyan Stefanov
JavaScript

JavaScript

David Flanagan
JavaScript

JavaScript

T. J. Crowder

Publisher Resources

ISBN: 9787519869601