SlideShare une entreprise Scribd logo
1  sur  36
Télécharger pour lire hors ligne
Pocket Authentication
with OAuth on Firefox OS
Mozilla Taiwan
Tommy Kuo [:KuoE0]
kuoe0@mozilla.com
Pocket Manipulation API
• Add API
https://getpocket.com/developer/docs/v3/add
• Modify API
https://getpocket.com/developer/docs/v3/modify
• Retrieve API
https://getpocket.com/developer/docs/v3/retrieve
Requirement
REQUIRED:
- consumer_key
- access_token
Pocket API
Get consumer_key from
https://getpocket.com/developer/apps/new.
Get access_token with Pocket Authentication API.
https://getpocket.com/developer/docs/authentication
Authenticate with Pocket account
Steps:
1. Obtain request_token.
2. Login & authenticate with request_token.
3. Convert request_token into access_token.
P.S.
1. Must be done over HTTPS.
2. Must be POST method.
Step 1. Obtain request_token.
Use consumer_key and redirect_uri to register and
obtain a request_token.
Step 1. Obtain request_token.
Use consumer_key and redirect_uri to register and
obtain a request_token.
The URI to redirect
after authentication.
post
https://getpocket.com/v3/oauth/request
consumer_key
redirect_uri{ }request_token
authenticate: function(callback) {
// get request token to open authentication page
this._post(
"https://getpocket.com/v3/oauth/request",
JSON.stringify({
consumer_key: this.CONSUMER_KEY,
redirect_uri: this.REDIRECT_URI
}),
response => {
this._openAuthenticationPage(response.code, callback);
}
);
}
Step 2. Login & authenticate with request_token.
Use requset_token to open the authentication page to
authenticate the request_token by user.
And the redirect_uri parameter to open authentication
page must be as same as the redirect_uri to register
request_token in step 1.
We need to open the page to
let user login and authorize.
https://getpocket.com/auth/authorize?
request_token=xxx&redirect_uri=yyy
We need to open the page to
let user login and authorize.
https://getpocket.com/auth/authorize?
request_token=xxx&redirect_uri=yyy
In Firefox OS, the redirect_uri can not work
with the app protocol.
We need to open the page to
let user login and authorize.
https://getpocket.com/auth/authorize?
request_token=xxx&redirect_uri=yyy
In Firefox OS, the redirect_uri can not work
with the app protocol.
We need to close the authentication page
after authentication.
open
https://getpocket.com/auth/authorize?
request_token=x&redirect_uri=y
mozbrowserlocationchange
location == redirect_uri
when
close
<iframe mozbrowser>
</iframe>
_openAuthenticationPage: function(requestToken, callback) {
var authUrl = ["https://getpocket.com/auth/authorize?request_token=", requestToken, "&redirect_uri=",
this.REDIRECT_URI].join("");
var authWin = document.createElement('iframe');
authWin.setAttribute('src', authUrl);
authWin.setAttribute('mozbrowser', true);
authWin.setAttribute('class', 'fullscreen');
authWin.addEventListener('mozbrowserlocationchange', evt => {
var url = new URL(evt.detail);
if (url.href == this.REDIRECT_URI) {
this._getAccessToken(requestToken, callback);
document.body.removeChild(authWin);
}
});
document.body.appendChild(authWin);
}
Step 3. Convert request_token into access_token.
Use the consumer_key and the authenticated
request_token to obtain access_token.
post
https://getpocket.com/v3/oauth/authorize
access_token
Convert the request_token into the access_token.
consumer_key
request_token{ }
_getAccessToken: function(requestToken, callback) {
this._post(
"https://getpocket.com/v3/oauth/authorize",
JSON.stringify({
consumer_key: this.CONSUMER_KEY,
code: requestToken
}),
response => {
this.ACCESS_TOKEN = response.access_token;
if (callback) {
callback();
}
}
);
}
Convert the request_token into the access_token.
Authenticate with Firefox account
Steps:
1. Obtain request_token.
2. Login with Firefox account.
3. Authenticate with request_token.
4. Convert request_token into access_token.
P.S.
1. Must be done over HTTPS.
2. Must be POST method.
Steps:
1. Obtain request_token.
2. Login with Firefox account.
3. Authenticate with request_token.
4. Convert request_token into access_token.
P.S.
1. Must be done over HTTPS.
2. Must be POST method.
Step 2. Login with Firefox account.
Log in with Firefox account. And the redirect_uri
information is missing when we redirect to the Firefox
account log-in page.
After Firefox account logged-in, we only let Firefox
account authorize Pocket to use the data in Firefox
account.
And then, this iframe will be redirected to Pocket and
should be closed.
open
https://getpocket.com/auth/authorize?
request_token=x&redirect_uri=y
mozbrowserlocationchange
Choose “Log in with Firefox”
click <iframe mozbrowser>
</iframe>
open
mozbrowserlocationchange
<iframe mozbrowser>
</iframe>
https://accounts.firefox.com/oauth/
signin?client_id=x&state=y&scope=z
open
mozbrowserlocationchange
<iframe mozbrowser>
</iframe>
https://accounts.firefox.com/oauth/
signin?client_id=x&state=y&scope=z
redirect_uri is missing
open
mozbrowserlocationchange
<iframe mozbrowser>
</iframe>
https://accounts.firefox.com/oauth/
signin?client_id=x&state=y&scope=z
redirect_uri is missing
open
mozbrowserlocationchange
<iframe mozbrowser>
</iframe>
https://getpocket.com/a/
redirect to Pocket
open
mozbrowserlocationchange
<iframe mozbrowser>
</iframe>
https://getpocket.com/a/
redirect to Pocket
redirect to Pocket
when
close
_openAuthenticationPage: function(requestToken, callback) {
var authUrl = ["https://getpocket.com/auth/authorize?request_token=", requestToken, "&redirect_uri=",
this.REDIRECT_URI].join("");
var authWin = document.createElement('iframe');
authWin.setAttribute('src', authUrl);
authWin.setAttribute('mozbrowser', true);
authWin.setAttribute('class', 'fullscreen');
authWin.addEventListener('mozbrowserlocationchange', evt => {
var url = new URL(evt.detail);
if (url.protocol + '//' + url.host + url.pathname == "https://getpocket.com/a/") {
document.body.removeChild(authWin);
this._openAuthenticationPage(requestToken, callback);
}
else if (url.href == this.REDIRECT_URI) {
this._getAccessToken(requestToken, callback);
document.body.removeChild(authWin);
_openAuthenticationPage: function(requestToken, callback) {
var authUrl = ["https://getpocket.com/auth/authorize?request_token=", requestToken, "&redirect_uri=",
this.REDIRECT_URI].join("");
var authWin = document.createElement('iframe');
authWin.setAttribute('src', authUrl);
authWin.setAttribute('mozbrowser', true);
authWin.setAttribute('class', 'fullscreen');
authWin.addEventListener('mozbrowserlocationchange', evt => {
var url = new URL(evt.detail);
if (url.protocol + '//' + url.host + url.pathname == "https://getpocket.com/a/") {
document.body.removeChild(authWin);
this._openAuthenticationPage(requestToken, callback);
}
else if (url.href == this.REDIRECT_URI) {
this._getAccessToken(requestToken, callback);
document.body.removeChild(authWin);
After logged in
_openAuthenticationPage: function(requestToken, callback) {
var authUrl = ["https://getpocket.com/auth/authorize?request_token=", requestToken, "&redirect_uri=",
this.REDIRECT_URI].join("");
var authWin = document.createElement('iframe');
authWin.setAttribute('src', authUrl);
authWin.setAttribute('mozbrowser', true);
authWin.setAttribute('class', 'fullscreen');
authWin.addEventListener('mozbrowserlocationchange', evt => {
var url = new URL(evt.detail);
if (url.protocol + '//' + url.host + url.pathname == "https://getpocket.com/a/") {
document.body.removeChild(authWin);
this._openAuthenticationPage(requestToken, callback);
}
else if (url.href == this.REDIRECT_URI) {
this._getAccessToken(requestToken, callback);
document.body.removeChild(authWin);
After logged in
Authenticate again!
Step 3. Authenticate with request_token.
When Pocket have been authorized by Firefox account,
it means the user have already logged in Pocket.
The next step is to let Pocket authenticate the
request_token. This step is as same as the step 2 to
authenticate with Pocket account.
open
https://getpocket.com/auth/authorize?
request_token=x&redirect_uri=y
mozbrowserlocationchange
location == redirect_uri
when
close
<iframe mozbrowser>
</iframe>
Thanks.

Contenu connexe

Tendances (9)

Integrating WordPress With Web APIs
Integrating WordPress With Web APIsIntegrating WordPress With Web APIs
Integrating WordPress With Web APIs
 
Accessing APIs using OAuth on the federated (WordPress) web
Accessing APIs using OAuth on the federated (WordPress) webAccessing APIs using OAuth on the federated (WordPress) web
Accessing APIs using OAuth on the federated (WordPress) web
 
JWT Authentication with AngularJS
JWT Authentication with AngularJSJWT Authentication with AngularJS
JWT Authentication with AngularJS
 
The dark side of the app
The dark side of the appThe dark side of the app
The dark side of the app
 
Spring security oauth2
Spring security oauth2Spring security oauth2
Spring security oauth2
 
Chatting with HIpChat: APIs 101
Chatting with HIpChat: APIs 101Chatting with HIpChat: APIs 101
Chatting with HIpChat: APIs 101
 
JavaOne 2014 - Securing RESTful Resources with OAuth2
JavaOne 2014 - Securing RESTful Resources with OAuth2JavaOne 2014 - Securing RESTful Resources with OAuth2
JavaOne 2014 - Securing RESTful Resources with OAuth2
 
SSL Screw Ups
SSL Screw UpsSSL Screw Ups
SSL Screw Ups
 
OAuth2 Protocol with Grails Spring Security
OAuth2 Protocol with Grails Spring SecurityOAuth2 Protocol with Grails Spring Security
OAuth2 Protocol with Grails Spring Security
 

Similaire à Pocket Authentication with OAuth on Firefox OS

Building @Anywhere (for TXJS)
Building @Anywhere (for TXJS)Building @Anywhere (for TXJS)
Building @Anywhere (for TXJS)
danwrong
 
Sfdc tournyc14 salesforceintegrationwithgoogledoubleclick__final_20141119
Sfdc tournyc14 salesforceintegrationwithgoogledoubleclick__final_20141119Sfdc tournyc14 salesforceintegrationwithgoogledoubleclick__final_20141119
Sfdc tournyc14 salesforceintegrationwithgoogledoubleclick__final_20141119
Ami Assayag
 
The Identity Problem of the Web and how to solve it
The Identity Problem of the Web and how to solve itThe Identity Problem of the Web and how to solve it
The Identity Problem of the Web and how to solve it
Bastian Hofmann
 

Similaire à Pocket Authentication with OAuth on Firefox OS (20)

OAuth 2.0
OAuth 2.0OAuth 2.0
OAuth 2.0
 
OAuth 2.0 – A standard is coming of age by Uwe Friedrichsen
OAuth 2.0 – A standard is coming of age by Uwe FriedrichsenOAuth 2.0 – A standard is coming of age by Uwe Friedrichsen
OAuth 2.0 – A standard is coming of age by Uwe Friedrichsen
 
Client-side Auth with Ember.js
Client-side Auth with Ember.jsClient-side Auth with Ember.js
Client-side Auth with Ember.js
 
How to implement authorization in your backend with AWS IAM
How to implement authorization in your backend with AWS IAMHow to implement authorization in your backend with AWS IAM
How to implement authorization in your backend with AWS IAM
 
Building @Anywhere (for TXJS)
Building @Anywhere (for TXJS)Building @Anywhere (for TXJS)
Building @Anywhere (for TXJS)
 
Integrating OAuth and Social Login Into Wordpress
Integrating OAuth and Social Login Into WordpressIntegrating OAuth and Social Login Into Wordpress
Integrating OAuth and Social Login Into Wordpress
 
GDG Cloud Taipei: Meetup #52 - Istio Security: API Authorization
GDG Cloud Taipei: Meetup #52 - Istio Security: API AuthorizationGDG Cloud Taipei: Meetup #52 - Istio Security: API Authorization
GDG Cloud Taipei: Meetup #52 - Istio Security: API Authorization
 
OAuth 2 Presentation
OAuth 2 PresentationOAuth 2 Presentation
OAuth 2 Presentation
 
(4) OAuth 2.0 Obtaining Authorization
(4) OAuth 2.0 Obtaining Authorization(4) OAuth 2.0 Obtaining Authorization
(4) OAuth 2.0 Obtaining Authorization
 
"Auth for React.js APP", Nikita Galkin
"Auth for React.js APP", Nikita Galkin"Auth for React.js APP", Nikita Galkin
"Auth for React.js APP", Nikita Galkin
 
Paypal REST api ( Japanese version )
Paypal REST api ( Japanese version )Paypal REST api ( Japanese version )
Paypal REST api ( Japanese version )
 
Securing APIs with OAuth 2.0
Securing APIs with OAuth 2.0Securing APIs with OAuth 2.0
Securing APIs with OAuth 2.0
 
import React, { useEffect } from react;import { BrowserRouter as.pdf
import React, { useEffect } from react;import { BrowserRouter as.pdfimport React, { useEffect } from react;import { BrowserRouter as.pdf
import React, { useEffect } from react;import { BrowserRouter as.pdf
 
Sfdc tournyc14 salesforceintegrationwithgoogledoubleclick__final_20141119
Sfdc tournyc14 salesforceintegrationwithgoogledoubleclick__final_20141119Sfdc tournyc14 salesforceintegrationwithgoogledoubleclick__final_20141119
Sfdc tournyc14 salesforceintegrationwithgoogledoubleclick__final_20141119
 
OAuth and Open-id
OAuth and Open-idOAuth and Open-id
OAuth and Open-id
 
OAuth2 and OpenID with Spring Boot
OAuth2 and OpenID with Spring BootOAuth2 and OpenID with Spring Boot
OAuth2 and OpenID with Spring Boot
 
FIWARE ID Management
FIWARE ID ManagementFIWARE ID Management
FIWARE ID Management
 
An introduction to Laravel Passport
An introduction to Laravel PassportAn introduction to Laravel Passport
An introduction to Laravel Passport
 
The Identity Problem of the Web and how to solve it
The Identity Problem of the Web and how to solve itThe Identity Problem of the Web and how to solve it
The Identity Problem of the Web and how to solve it
 
Mashing up JavaScript
Mashing up JavaScriptMashing up JavaScript
Mashing up JavaScript
 

Plus de Chih-Hsuan Kuo

[ACM-ICPC] Tree Isomorphism
[ACM-ICPC] Tree Isomorphism[ACM-ICPC] Tree Isomorphism
[ACM-ICPC] Tree Isomorphism
Chih-Hsuan Kuo
 
[ACM-ICPC] Dinic's Algorithm
[ACM-ICPC] Dinic's Algorithm[ACM-ICPC] Dinic's Algorithm
[ACM-ICPC] Dinic's Algorithm
Chih-Hsuan Kuo
 
[ACM-ICPC] Disjoint Set
[ACM-ICPC] Disjoint Set[ACM-ICPC] Disjoint Set
[ACM-ICPC] Disjoint Set
Chih-Hsuan Kuo
 

Plus de Chih-Hsuan Kuo (20)

Rust
RustRust
Rust
 
[Mozilla] content-select
[Mozilla] content-select[Mozilla] content-select
[Mozilla] content-select
 
Ownership System in Rust
Ownership System in RustOwnership System in Rust
Ownership System in Rust
 
在開始工作以前,我以為我會寫扣。
在開始工作以前,我以為我會寫扣。在開始工作以前,我以為我會寫扣。
在開始工作以前,我以為我會寫扣。
 
Effective Modern C++ - Item 35 & 36
Effective Modern C++ - Item 35 & 36Effective Modern C++ - Item 35 & 36
Effective Modern C++ - Item 35 & 36
 
Use C++ to Manipulate mozSettings in Gecko
Use C++ to Manipulate mozSettings in GeckoUse C++ to Manipulate mozSettings in Gecko
Use C++ to Manipulate mozSettings in Gecko
 
Necko walkthrough
Necko walkthroughNecko walkthrough
Necko walkthrough
 
Protocol handler in Gecko
Protocol handler in GeckoProtocol handler in Gecko
Protocol handler in Gecko
 
面試面試面試,因為很重要所以要說三次!
面試面試面試,因為很重要所以要說三次!面試面試面試,因為很重要所以要說三次!
面試面試面試,因為很重要所以要說三次!
 
應徵軟體工程師
應徵軟體工程師應徵軟體工程師
應徵軟體工程師
 
面試心得分享
面試心得分享面試心得分享
面試心得分享
 
Windows 真的不好用...
Windows 真的不好用...Windows 真的不好用...
Windows 真的不好用...
 
Python @Wheel Lab
Python @Wheel LabPython @Wheel Lab
Python @Wheel Lab
 
Introduction to VP8
Introduction to VP8Introduction to VP8
Introduction to VP8
 
Python @NCKU CSIE
Python @NCKU CSIEPython @NCKU CSIE
Python @NCKU CSIE
 
[ACM-ICPC] Tree Isomorphism
[ACM-ICPC] Tree Isomorphism[ACM-ICPC] Tree Isomorphism
[ACM-ICPC] Tree Isomorphism
 
[ACM-ICPC] Dinic's Algorithm
[ACM-ICPC] Dinic's Algorithm[ACM-ICPC] Dinic's Algorithm
[ACM-ICPC] Dinic's Algorithm
 
[ACM-ICPC] Disjoint Set
[ACM-ICPC] Disjoint Set[ACM-ICPC] Disjoint Set
[ACM-ICPC] Disjoint Set
 
[ACM-ICPC] Traversal
[ACM-ICPC] Traversal[ACM-ICPC] Traversal
[ACM-ICPC] Traversal
 
[ACM-ICPC] UVa-10245
[ACM-ICPC] UVa-10245[ACM-ICPC] UVa-10245
[ACM-ICPC] UVa-10245
 

Dernier

Artificial Intelligence: Facts and Myths
Artificial Intelligence: Facts and MythsArtificial Intelligence: Facts and Myths
Artificial Intelligence: Facts and Myths
Joaquim Jorge
 

Dernier (20)

Workshop - Best of Both Worlds_ Combine KG and Vector search for enhanced R...
Workshop - Best of Both Worlds_ Combine  KG and Vector search for  enhanced R...Workshop - Best of Both Worlds_ Combine  KG and Vector search for  enhanced R...
Workshop - Best of Both Worlds_ Combine KG and Vector search for enhanced R...
 
Boost PC performance: How more available memory can improve productivity
Boost PC performance: How more available memory can improve productivityBoost PC performance: How more available memory can improve productivity
Boost PC performance: How more available memory can improve productivity
 
Understanding Discord NSFW Servers A Guide for Responsible Users.pdf
Understanding Discord NSFW Servers A Guide for Responsible Users.pdfUnderstanding Discord NSFW Servers A Guide for Responsible Users.pdf
Understanding Discord NSFW Servers A Guide for Responsible Users.pdf
 
[2024]Digital Global Overview Report 2024 Meltwater.pdf
[2024]Digital Global Overview Report 2024 Meltwater.pdf[2024]Digital Global Overview Report 2024 Meltwater.pdf
[2024]Digital Global Overview Report 2024 Meltwater.pdf
 
04-2024-HHUG-Sales-and-Marketing-Alignment.pptx
04-2024-HHUG-Sales-and-Marketing-Alignment.pptx04-2024-HHUG-Sales-and-Marketing-Alignment.pptx
04-2024-HHUG-Sales-and-Marketing-Alignment.pptx
 
08448380779 Call Girls In Diplomatic Enclave Women Seeking Men
08448380779 Call Girls In Diplomatic Enclave Women Seeking Men08448380779 Call Girls In Diplomatic Enclave Women Seeking Men
08448380779 Call Girls In Diplomatic Enclave Women Seeking Men
 
Artificial Intelligence: Facts and Myths
Artificial Intelligence: Facts and MythsArtificial Intelligence: Facts and Myths
Artificial Intelligence: Facts and Myths
 
Presentation on how to chat with PDF using ChatGPT code interpreter
Presentation on how to chat with PDF using ChatGPT code interpreterPresentation on how to chat with PDF using ChatGPT code interpreter
Presentation on how to chat with PDF using ChatGPT code interpreter
 
Real Time Object Detection Using Open CV
Real Time Object Detection Using Open CVReal Time Object Detection Using Open CV
Real Time Object Detection Using Open CV
 
Advantages of Hiring UIUX Design Service Providers for Your Business
Advantages of Hiring UIUX Design Service Providers for Your BusinessAdvantages of Hiring UIUX Design Service Providers for Your Business
Advantages of Hiring UIUX Design Service Providers for Your Business
 
Automating Google Workspace (GWS) & more with Apps Script
Automating Google Workspace (GWS) & more with Apps ScriptAutomating Google Workspace (GWS) & more with Apps Script
Automating Google Workspace (GWS) & more with Apps Script
 
08448380779 Call Girls In Greater Kailash - I Women Seeking Men
08448380779 Call Girls In Greater Kailash - I Women Seeking Men08448380779 Call Girls In Greater Kailash - I Women Seeking Men
08448380779 Call Girls In Greater Kailash - I Women Seeking Men
 
Data Cloud, More than a CDP by Matt Robison
Data Cloud, More than a CDP by Matt RobisonData Cloud, More than a CDP by Matt Robison
Data Cloud, More than a CDP by Matt Robison
 
08448380779 Call Girls In Friends Colony Women Seeking Men
08448380779 Call Girls In Friends Colony Women Seeking Men08448380779 Call Girls In Friends Colony Women Seeking Men
08448380779 Call Girls In Friends Colony Women Seeking Men
 
How to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected WorkerHow to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected Worker
 
The 7 Things I Know About Cyber Security After 25 Years | April 2024
The 7 Things I Know About Cyber Security After 25 Years | April 2024The 7 Things I Know About Cyber Security After 25 Years | April 2024
The 7 Things I Know About Cyber Security After 25 Years | April 2024
 
Exploring the Future Potential of AI-Enabled Smartphone Processors
Exploring the Future Potential of AI-Enabled Smartphone ProcessorsExploring the Future Potential of AI-Enabled Smartphone Processors
Exploring the Future Potential of AI-Enabled Smartphone Processors
 
2024: Domino Containers - The Next Step. News from the Domino Container commu...
2024: Domino Containers - The Next Step. News from the Domino Container commu...2024: Domino Containers - The Next Step. News from the Domino Container commu...
2024: Domino Containers - The Next Step. News from the Domino Container commu...
 
08448380779 Call Girls In Civil Lines Women Seeking Men
08448380779 Call Girls In Civil Lines Women Seeking Men08448380779 Call Girls In Civil Lines Women Seeking Men
08448380779 Call Girls In Civil Lines Women Seeking Men
 
Driving Behavioral Change for Information Management through Data-Driven Gree...
Driving Behavioral Change for Information Management through Data-Driven Gree...Driving Behavioral Change for Information Management through Data-Driven Gree...
Driving Behavioral Change for Information Management through Data-Driven Gree...
 

Pocket Authentication with OAuth on Firefox OS