Tutorial
Select the API you want to start with:
Use OAuth API with Facebook
1. Sign up for an Apigee Free account or Sign in.
2. Create an application on apigee.com
- Visit: https://apigee.com/oauth_api
- Click on the Add App button to launch the setup form.
- Name your OAuth API App.
- Confirm that the Base URL is what you want for your app.(You’ll make all API calls through this URL.).
- Click Create Base URL.
3. Add Facebook to your App
- At Apigee OAuth API app setup form...
- Select Facebook from the API Providers dropdown.
- Copy the Site URL, you’ll need this for Facebook
- View details of creating applications in Facebook (opens in new window).
- Visit https://developers.facebook.com/apps to launch a new window/tab with Facebook.
- Sign in to Facebook and create a new application.
- Fill out the form.
- Accept terms and create your Facebook App.
- Paste the Site URL in the integration section for "website"
- Copy your Facebook App App ID and paste it into the Apigee OAuth API setup form.
- Copy your Facebook App App Secret and paste it into the Apigee OAuth API setup form.
- Click Finish to complete your OAuth API App.
- When you return to the OAuth API apps list page, make a note of your Base URL, you'll need this later.
4. Add a User for your App
Every user of your app gets a unique token, called a SmartKey. Every time you create a user, you get a SmartKey in return. Apigee will associate Facebook credentials with that SmartKey.
So now you'll create your first user. The fastest way is to use the Apigee Console to make an API request to the OAuth API. This will help teach you how to use the OAuth API so that when you're ready, you can build support for adding user into your app.
- In the Console
- Click on the Service dropdown and select the base URL: https://{appname}-api.apigee.com/v1
- Choose the expand method list icon and select the Create User method from the Managing Users group
- On the Template tab, supply your app name as the value
- One the Body tab and supply the values for userName, fullName, and password
- Send your request
- Expect a response that looks like the following: applicationUserId: 322, fullName: "Demo User1", smartKey: "4ec64ef1-7361-456e-95cf-562ed39fddd3", userName: "demouser1", appName: "apigeedemoapp"
- Make a note of the SmartKey value you get from the Console. You’ll use that next.
Authenticate the user with Facebook
- Open a new browser window
- Assemble the AuthURL for Facebook. Copy and paste this into your location bar: https://REPLACE_WITH_YOUR_APPNAME-api.apigee.com/v1/providers/facebook/authorize?smartkey=PASTE_SMARTKEY
- Paste your Auth URL to initiate the OAuth Dance with Facebook.
- Change the appname to your appname in the URI.
- Change the smartkey for a user that has been authorized with Facebook on the end of the URI.
- Hit return to submit the URL.(You'll be redirected to Facebook).
- After signing in with Facebook and authorizing the app to access Facebook, you’re done.
- That’s it! All of the credential updating for your user is done behind the scenes in the Apigee Gateway.
5. Make authenticated requests with a Smartkey
- Open a new browser window
- Copy and paste this into your location bar: https://REPLACE_WITH_YOUR_APPNAME-api.apigee.com/v1/facebook/me?smartkey=PASTE_SMARTKEY
- Change the appname to your appname in the URI.
- Change the smartkey for a user that has been authorized with Facebook on the end of the URI.
- Hit return to submit the URL.
- You should see the JSON of a Facebook response, without any of the mess with OAUTH.