44
Hands-on with OAuth, Facebook and the Force.com Platform Pat Patterson Principal Developer Evangelist salesforce.com [email protected] @metadaddy

Hands-on with OAuth, Facebook and the Force.com Platform

Embed Size (px)

DESCRIPTION

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.

Citation preview

Page 1: Hands-on with OAuth, Facebook and the Force.com Platform

Hands-on with OAuth, Facebook and the Force.com Platform

Pat PattersonPrincipal Developer [email protected]

@metadaddy

Page 2: Hands-on with OAuth, Facebook and the Force.com Platform

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.

Page 3: Hands-on with OAuth, Facebook and the Force.com Platform

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:15 Break

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

Page 4: Hands-on with OAuth, Facebook and the Force.com Platform

http://lanyrd.com/sryxw

Materials

Page 5: Hands-on with OAuth, Facebook and the Force.com Platform

OAuth 2.0

Page 6: Hands-on with OAuth, Facebook and the Force.com Platform

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

Page 7: Hands-on with OAuth, Facebook and the Force.com Platform

OAuth Roles

Page 8: Hands-on with OAuth, Facebook and the Force.com Platform

OAuth 2.0 Protocol

BrowserAuthorization

Server Client AppGET /something

302 FoundLocation: https://login.ex.com/?response_type=code&client_id=…&redirect_uri=…&scope=…GET /?response_type=...

302 FoundLocation: https://app.cl.com?

code=… GET /app.cl.com?code=…

Resource Server

Authenticate

POST /tokencode=…&grant_type=authorization_code&client_id=…

&client_secret=…&redirect_uri=…

GET /dataAuthorization: Bearer 00D5…

200 OK{ “access_token”: “00D5…”}

200 OKData200 OK

Some Content

Page 9: Hands-on with OAuth, Facebook and the Force.com Platform

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

Page 10: Hands-on with OAuth, Facebook and the Force.com Platform

Social Sign-On

Page 11: Hands-on with OAuth, Facebook and the Force.com Platform

CRM processes havehistorically been

disconnected

Page 12: Hands-on with OAuth, Facebook and the Force.com Platform
Page 13: Hands-on with OAuth, Facebook and the Force.com Platform
Page 14: Hands-on with OAuth, Facebook and the Force.com Platform
Page 15: Hands-on with OAuth, Facebook and the Force.com Platform
Page 16: Hands-on with OAuth, Facebook and the Force.com Platform
Page 17: Hands-on with OAuth, Facebook and the Force.com Platform

The Social Enterprise

communicates in new ways…

Page 18: Hands-on with OAuth, Facebook and the Force.com Platform
Page 19: Hands-on with OAuth, Facebook and the Force.com Platform
Page 20: Hands-on with OAuth, Facebook and the Force.com Platform

…but how do social customers and

partners directly engage with your

products and services?

Page 21: Hands-on with OAuth, Facebook and the Force.com Platform

Introducing Social Sign-On

Page 22: Hands-on with OAuth, Facebook and the Force.com Platform

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

Page 23: Hands-on with OAuth, Facebook and the Force.com Platform

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

Page 24: Hands-on with OAuth, Facebook and the Force.com Platform

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

Page 25: Hands-on with OAuth, Facebook and the Force.com Platform

Exercise 1

Page 26: Hands-on with OAuth, Facebook and the Force.com Platform

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

Page 27: Hands-on with OAuth, Facebook and the Force.com Platform

The Facebook Graph API

Page 28: Hands-on with OAuth, Facebook and the Force.com Platform

The Facebook Graph API

https://developers.facebook.com/docs/reference/api/

Page 29: Hands-on with OAuth, Facebook and the Force.com Platform

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

Page 30: Hands-on with OAuth, Facebook and the Force.com Platform

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

Page 31: Hands-on with OAuth, Facebook and the Force.com Platform

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

Page 32: Hands-on with OAuth, Facebook and the Force.com Platform

Searching

Search via https://graph.facebook.com/search

GET https://graph.facebook.com/search?

q=force.com&type=post&access_token=AAA

Page 33: Hands-on with OAuth, Facebook and the Force.com Platform

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"}

Page 34: Hands-on with OAuth, Facebook and the Force.com Platform

Graph API Explorer

https://developers.facebook.com/tools/explorer

Page 35: Hands-on with OAuth, Facebook and the Force.com Platform

The Force.com Toolkit for Facebook

Page 36: Hands-on with OAuth, Facebook and the Force.com Platform

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

Page 37: Hands-on with OAuth, Facebook and the Force.com Platform

Force.com Toolkit for Facebook

Apex binding for the Facebook Graph APIMap<String,String> params =

new Map<string,string>{'fields' => 'id,name',

'limit' => '10'};

FacebookUsers friendsList =

new FacebookUsers(access_token, 'me/friends', params);

for (FacebookUser u : friendsList.data) {

System.debug(u.name);

}

Graph API objects modeled as Apex classes– FacebookUser, FacebookPhoto etc

Open source, but unsupported

Page 38: Hands-on with OAuth, Facebook and the Force.com Platform

Exercise 2

Page 39: Hands-on with OAuth, Facebook and the Force.com Platform

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?

Page 40: Hands-on with OAuth, Facebook and the Force.com Platform

Roadmap

Page 41: Hands-on with OAuth, Facebook and the Force.com Platform

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

Page 42: Hands-on with OAuth, Facebook and the Force.com Platform

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

Page 43: Hands-on with OAuth, Facebook and the Force.com Platform

Q & A

Page 44: Hands-on with OAuth, Facebook and the Force.com Platform