Step Up 2 Salesforce
The fitness app for SFDC, as made at the Summer of Hacks 2014 in NYC.
Forked from https://github.com/jesperfj/sfdc-oauth-playground.
This app is still a work in progress, but if you want to play around with it right now in a dev org, here's how to get up and running:
- Register your app at http://dev.fitbit.com. Give the app read-only access and no callback URL is needed.
- Deploy package into your org.
- Enable the Step Up app for your user profile.
- Enable "Fitbit Keys" and "Link to Fitbit" tabs for your user profile.
- Go to "Fitbit Keys" tab and enter your Fitbit API creditentials.
- Schedule the "Fitbit_NightlyBatch_Schedule" Apex Class to run every night, ideally around 4:00 am.
- Setup -> Security -> Remote site settings and add the https://api.fitbit.com/ endpoint
- Setup -> Administer -> Mobile Administration -> Mobile Navigation and add "Link to Fitbit" to the mobile navbar.
- Boot up Salesforce1 and go to "Link to Fitbit" tab to OAuth into your Fitbit account.
The data should be synced every night and you'll get a Chatter post giving you props if you had the most steps the previous day.
More to come as I polish up this app, but for now, here is the README file for the SFDC OAuth Playground app.
Apex OAuth Consumer with Test Playground
This project was copied over from http://code.google.com/p/sfdc-oauth-playground/, since I do all my projects on github now. I don't expect to make any changes, so the two locations will likely stay in sync but this is now the main project home.
This project provides a basic Oauth1 consumer implementation in Apex. It defines objects for storing keys and secrets for multiple services and users. It also comes with an API "playground" where you can try out API calls to your Oauth services.
Note that as OAuth service providers gradually switch to the much simpler OAuth2, this project will become of limited value. There are currently no plans to upgrade this project to OAuth2 as the main point was to help developers with the tricky parts of OAuth1. If you see any value in having this project support OAuth2, drop me a note and/or fork it.
About this project
The main purpose of this project is to show how to write OAuth signed requests in Apex, but it expanded beyond that to a more full fledged OAuth consumer playground. It comes with a set of custom objects for storing OAuth service configuration and OAuth tokens on behalf of users in the org.
IMPORT SECURITY NOTE: When you authorize access to a remote service, your personal and very private access token and secret are stored in a custom object. Do not use this app in an org where you do not trust users who may access this object (OAuth_Token__c). At the very least, administrators will have access to the data.
The project also comes with functionality for authorizing access, including authorization redirects and callbacks.
Finally, the project includes an API Tester that you can use to make API requests to services that have been authorized for access.
The code has been tested with the following services:
- Google (Contacts, Calendar, Portable Contacts)
- LinkedIn (can't get status API to work, but the OAuth part works fine)
- Salesforce (works except that redirects can get confused if on same instance)
Yahoo couldn't be tested because it wasn't possible to have a Yahoo application verified. Yahoo requires you to host an HTML page on your root path (/) with a certain code in it. This is currently not possibe with Force.com sites. Google has a similar verification mechanism but they give you the option to include the code in a meta tag on any page on your site which works better.
The OAuth class is the meat of the project. It relies on the OAuth_Service__c and OAuth_Token__c for storage and retrieval of tokens and service configuration, but it can easily be rewritten as a stand-alone class that can be used for a more specific application.
Visual Force Controller for authorization flow
VF Controller for the API Test page. This page includes a feature that allows you to save URLs (API endpoints), including post data for later use.
Copyright (c) 2009 Jesper Joergensen
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.