OAuth 2.0 is now the default mechanism for authorizing access to Web services APIs, supported by providers across the Internet. In this workshop, aimed at developers and architects, we will look at the OAuth 2.0 protocol, build a portal on Force.com that acquires customers via Facebook, logs them in via OAuth 2.0, and use the Facebook Graph API to create a social application, combining business data in Force.com with users' social graphs in Facebook. Bring a laptop with a web browser and a text editor - no development environment needed - we'll be coding in the cloud, baby!
Presented at Cloud Identity Summit 2012.
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...
Hands-on with OAuth, Facebook and the Force.com Platform
1. Hands-on with
OAuth, Facebook and the
Force.com Platform
Pat Patterson
Principal Developer Evangelist
salesforce.com
ppatterson@salesforce.com
@metadaddy
2. Safe Harbor
Safe harbor statement under the Private Securities Litigation Reform Act of 1995: This presentation may
contain forward-looking statements that involve risks, uncertainties, and assumptions. If any such uncertainties
materialize or if any of the assumptions proves incorrect, the results of salesforce.com, inc. could differ
materially from the results expressed or implied by the forward-looking statements we make. All statements
other than statements of historical fact could be deemed forward-looking, including any projections of
subscriber growth, earnings, revenues, or other financial items and any statements regarding strategies or
plans of management for future operations, statements of belief, any statements concerning new, planned, or
upgraded services or technology developments and customer contracts or use of our services.
The risks and uncertainties referred to above include – but are not limited to – risks associated with developing
and delivering new functionality for our service, our new business model, our past operating losses, possible
fluctuations in our operating results and rate of growth, interruptions or delays in our Web hosting, breach of
our security measures, risks associated with possible mergers and acquisitions, the immature market in which
we operate, our relatively limited operating history, our ability to expand, retain, and motivate our employees
and manage our growth, new releases of our service and successful customer deployment, our limited history
reselling non-salesforce.com products, and utilization and selling to larger enterprise customers. Further
information on potential factors that could affect the financial results of salesforce.com, inc. is included in our
annual report on Form 10-K for the most recent fiscal year ended January 31, 2012. This document and
others are available on the SEC Filings section of the Investor Information section of our Web site.
Any unreleased services or features referenced in this or other press releases or public statements are not
currently available and may not be delivered on time or at all. Customers who purchase our services should
make the purchase decisions based upon features that are currently available. Salesforce.com, inc. assumes
no obligation and does not intend to update these forward-looking statements.
3. Agenda
1:05 Introductions
1:15 The OAuth 2.0 Authorization Framework
1:25 Social Sign-On with Authentication Providers
1:45 Exercise 1: Configure an Auth Provider
2:15Break
2:30 The Facebook Graph API
2:45 The Force.com Toolkit for Facebook
3:00 Exercise 2: Create a Social Application
3:30 Roadmap
3:45 Q&A
6. OAuth 2.0
Authorization for RESTful APIs
Evolution of Google AuthSub, Yahoo BBAuth, AOL
OpenAuth etc
„Valet key‟ for the web
Emphasis on simplicity, ease of implementation
8. OAuth 2.0 Protocol
Authorization Resource
Server Browser Client App Server
GET /something
302 Found
Location:
https://login.ex.com/?response_t
ype=code&client_id=…&redirect
GET /?response_type=... _uri=…&scope=…
Authenticate
302 Found
Location:
https://app.cl.com?code=… GET /app.cl.com?code=…
POST /token
code=…&grant_type=authorization_code&client_id=…&client_secre
t=…&redirect_uri=…
200 OK
{ “access_token”: “00D5…”} GET /data
Authorization: Bearer 00D5…
200 OK
200 OK Data
Some Content
9. Force.com Identity Service
OAuth response contains „id‟ element:
{
"access_token": "00D5...”,
"id":
"https://login.salesforce.com/id/00D50000000IZ3ZEAW/005
50000001fg5OAAQ",
"instance_url": "https://na1.salesforce.com",
"issued_at": "1308806720993",
"signature": "GhBp..."
}
We can access this URL (with the OAuth token) to obtain
information on the user
Same pattern as OpenID Connect
22. Social Sign-On
– Automatically create and update users and contacts
– Single Sign-On makes it easy and keeps them coming back
– Deliver applications and services to deepen your relationship
– Active engagement automatically updates your customer data
23. So what’s under the covers?
The Auth Providers Framework
– Pre-integrated Single Sign-On from branded Identity Services
– Automatically create and update Contacts and Users
– Full control over data modeling with Apex Registration Handlers
– Works for both internal and external users
Out of the box support
– Facebook: B2C
– Salesforce: B2B
– JanRain: Breadth & Depth support for a wide catalog of Identity
Providers
24. When to use Auth Providers
Business to Consumer
– Use Facebook or JanRain for more options
Business to Partner
– Use Login with Salesforce for collaborating with Partners or
Customers that have existing Salesforce deployments
– Use SAML for point to point federations
Business to Employee
– SAML is still the preferred option ( see roadmap )
– SAML provides static
26. Exercise 1: Configure an Auth Provider
Create a Force.com Developer Edition environment
Create a Customer Portal
Create a Force.com Site, and link it to the portal
Create a Facebook App
Create an Authentication Provider
Create a login page for the portal
Login to the portal from Facebook
28. The Facebook Graph API
https://developers.facebook.com/docs/reference/api/
29. Accessing Social Graph Objects
Every social graph object has a unique ID
– https://graph.facebook.com/ID
For example, Facebook Platform has ID 19292868552
– GET https://graph.facebook.com/19292868552
30. Relationships – Edges on the Graph
Friends, feed (wall), likes, photos, videos, etc
Graph API terminology: connections
– https://graph.facebook.com/ID/CONNECTION_TYPE
For example, my friends
– Special ID - me
– GET https://graph.facebook.com/me/friends
31. Graph API Authorization
OAuth 2.0
– Obtain access token representing user‟s permission to access
their social graph
– Supply it with Graph API calls as a query parameter
• https://graph.facebook.com/ID?access_token=TOKENVALUE
Access to specific types of graph objects is controlled
by permissions
– user_likes, friends_photos, publish_stream etc
– Requested via OAuth 2.0 scope
– Balance app functionality against intrusiveness
32. Searching
Search via https://graph.facebook.com/search
GET
https://graph.facebook.com/search?q=force.com&type=
post&access_token=AAA
33. Publishing
HTTP POST to a connection URL
– Access token is required!
– curl -F 'access_token=...'
-F 'message=Hello world!'
https://graph.facebook.com/me/feed
– Response: {"id":"667905711_10151088147280712"}
36. Sidebar: Writing Apps for Force.com
Platform-as-a-Service
– Apps run on the Salesforce infrastructure
Model-View-Controller architecture
– Model = database.com
– View = Visualforce
– Controller = Apex
Force.com Workbook is a great place
to start
– http://developer.force.com/workbook
37. Force.com Toolkit for Facebook
Apex binding for the Facebook Graph API
Map<String,String>params =
new Map<string,string>{'fields' => 'id,name',
'limit' => '10'};
FacebookUsersfriendsList =
new FacebookUsers(access_token, 'me/friends', params);
for (FacebookUseru : friendsList.data) {
System.debug(u.name);
}
Graph API objects modeled as Apex classes
– FacebookUser, FacebookPhotoetc
Open source, but unsupported
39. Exercise 2: Create a Social Application
Add a Visualforce page to the portal
Retrieve the user‟s friends list
Expand the requested scope
Retrieve the user‟s photos
Think – what could I do next?
41. Roadmap for Auth Providers
StartURLs and Custom Scopes
– Pilot during Summer 12 timeframe
Communities, Site.com, and Orgs
– Authentication for Collaboration, Marketing, and multi-org single
sign-on
Make it great for employees
– Tie into My Domains so it works just like SAML
42. Resources
Force.com Workbook
http://developer.force.com/workbook
Digging Deeper into OAuth 2.0 on Force.com
http://bit.ly/oauth2-force
Social Single Sign-On – Authentication Providers in Spring ‟12
http://bit.ly/sso-authproviders
Janrain Social Sign-On
http://janrain.com/salesforce
Spring „12 Release Notes
http://developer.force.com/releases/release/Spring12
Force.com Toolkit for Facebook
http://wiki.developerforce.com/page/Facebook_Toolkit21
This is a fairly typical model. Sales rep starts their day with working on some opportunities
They find and pull up a contact
They interact with them,collect some data, log calls and activities and put it in your database
And you end up fillingyour CRM database with all of these Identities….which is good, but the customer isn’t directly engaged
Increasingly your customers and partners are out on Social Networks interacting with each other, discussing your products and brand
We’re giving you the tools like Social Accounts and Contacts to provides your sales users with social sales intelligence that they can use to better meet existing and potential customers’ needs.
And tools like radian6 to monitor and engage with customers