An implementation of the 500px OAuth flow for Meteor. Can be used also as a standalone OAuth client.
Created
May 23, 2015 06:39
-
-
Save illuminaut/cc8fcbfc0ac82c13e690 to your computer and use it in GitHub Desktop.
An implementation of the 500px OAuth flow for Meteor.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Auto detect text files and perform LF normalization | |
* text=auto | |
# Custom for Visual Studio | |
*.cs diff=csharp | |
# Standard to msysgit | |
*.doc diff=astextplain | |
*.DOC diff=astextplain | |
*.docx diff=astextplain | |
*.DOCX diff=astextplain | |
*.dot diff=astextplain | |
*.DOT diff=astextplain | |
*.pdf diff=astextplain | |
*.PDF diff=astextplain | |
*.rtf diff=astextplain | |
*.RTF diff=astextplain |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
.idea | |
# Windows image file caches | |
Thumbs.db | |
ehthumbs.db | |
# Folder config file | |
Desktop.ini | |
# Recycle Bin used on file shares | |
$RECYCLE.BIN/ | |
# Windows Installer files | |
*.cab | |
*.msi | |
*.msm | |
*.msp | |
# Windows shortcuts | |
*.lnk | |
# ========================= | |
# Operating System Files | |
# ========================= | |
# OSX | |
# ========================= | |
.DS_Store | |
.AppleDouble | |
.LSOverride | |
# Thumbnails | |
._* | |
# Files that might appear on external disk | |
.Spotlight-V100 | |
.Trashes | |
# Directories potentially created on remote AFP share | |
.AppleDB | |
.AppleDesktop | |
Network Trash Folder | |
Temporary Items | |
.apdisk |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
500px |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?xml version="1.0" encoding="UTF-8"?> | |
<module type="WEB_MODULE" version="4"> | |
<component name="NewModuleRootManager"> | |
<content url="file://$MODULE_DIR$" /> | |
<orderEntry type="inheritedJdk" /> | |
<orderEntry type="sourceFolder" forTests="false" /> | |
</component> | |
</module> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?xml version="1.0" encoding="UTF-8"?> | |
<project version="4"> | |
<component name="ProjectLevelVcsManager" settingsEditedManually="false"> | |
<OptionsSetting value="true" id="Add" /> | |
<OptionsSetting value="true" id="Remove" /> | |
<OptionsSetting value="true" id="Checkout" /> | |
<OptionsSetting value="true" id="Update" /> | |
<OptionsSetting value="true" id="Status" /> | |
<OptionsSetting value="true" id="Edit" /> | |
<ConfirmationsSetting value="0" id="Add" /> | |
<ConfirmationsSetting value="0" id="Remove" /> | |
</component> | |
<component name="ProjectRootManager" version="2" /> | |
</project> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?xml version="1.0" encoding="UTF-8"?> | |
<project version="4"> | |
<component name="ProjectModuleManager"> | |
<modules> | |
<module fileurl="file://$PROJECT_DIR$/.idea/500px.iml" filepath="$PROJECT_DIR$/.idea/500px.iml" /> | |
</modules> | |
</component> | |
</project> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?xml version="1.0" encoding="UTF-8"?> | |
<project version="4"> | |
<component name="VcsDirectoryMappings"> | |
<mapping directory="$PROJECT_DIR$" vcs="Git" /> | |
</component> | |
</project> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
_500px = {}; | |
// Request 500px credentials for the user | |
// @param options {optional} XXX support options.requestPermissions | |
// @param credentialRequestCompleteCallback {Function} Callback function to call on | |
// completion. Takes one argument, credentialToken on success, or Error on | |
// error. | |
Fitbit.requestCredential = function (options, credentialRequestCompleteCallback) { | |
// support both (options, callback) and (callback). | |
if (!credentialRequestCompleteCallback && typeof options === 'function') { | |
credentialRequestCompleteCallback = options; | |
options = {}; | |
} | |
var config = ServiceConfiguration.configurations.findOne({service: '500px'}); | |
if (!config) { | |
credentialRequestCompleteCallback && credentialRequestCompleteCallback( | |
new ServiceConfiguration.ConfigError()); | |
return; | |
} | |
var credentialToken = Random.secret(); | |
// We need to keep credentialToken across the next two 'steps' so we're adding | |
// a credentialToken parameter to the url and the callback url that we'll be returned | |
// to by oauth provider | |
var loginStyle = OAuth._loginStyle('500px', config, options); | |
// url to app, enters "step 1" as described in | |
// packages/accounts-oauth1-helper/oauth1_server.js | |
var loginPath = '_oauth/500px/?requestTokenAndRedirect=true' + '&state=' + OAuth._stateParam(loginStyle, credentialToken); | |
if (Meteor.isCordova) { | |
loginPath = loginPath + "&cordova=true"; | |
if (/Android/i.test(navigator.userAgent)) { | |
loginPath = loginPath + "&android=true"; | |
} | |
} | |
var loginUrl = Meteor.absoluteUrl(loginPath); | |
OAuth.launchLogin({ | |
loginService: "500px", | |
loginStyle: loginStyle, | |
loginUrl: loginUrl, | |
credentialRequestCompleteCallback: credentialRequestCompleteCallback, | |
credentialToken: credentialToken | |
}); | |
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<template name="configureLoginServiceDialogFor500px"> | |
<p> | |
First, you'll need to register your app on Fitbit. Follow these steps: | |
</p> | |
<ol> | |
<li> | |
Visit <a href="https://500px.com/settings/applications" target="_blank">https://500px.com/settings/applications</a> | |
</li> | |
<li> | |
Click "Register your application". | |
</li> | |
<li> | |
Complete the form with information about your client application. | |
</li> | |
<li> | |
Submit the form. | |
</li> | |
<li> | |
Click "See application details" to view your Client ID and Client Secret. | |
</li> | |
<li> | |
Make a note of your new application's Key (client ID) and Secret (client secret). You should keep your Secret private in a secure location. | |
</li> | |
</ol> | |
</template> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Template.configureLoginServiceDialogFor500px.helpers({ | |
siteUrl: function () { | |
return Meteor.absoluteUrl(); | |
} | |
}); | |
Template.configureLoginServiceDialogFor500px.fields = function () { | |
return [ | |
{property: 'client_id', label: 'Client ID'}, | |
{property: 'secret', label: 'Client Secret'} | |
]; | |
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
_500px = {}; | |
urls = { | |
requestToken: "https://api.500px.com/v1/oauth/request_token", | |
authorize: "https://api.500px.com/v1/oauth/authorize", | |
accessToken: "https://api.500px.com/v1/oauth/access_token", | |
authenticate: "https://api.500px.com/v1/oauth/authorize" | |
}; | |
_500px.whitelistedFields = ['fullname','userpic_url','email','photos_count','affection','in_favorites_count','friends_count','followers_count']; | |
Oauth.registerService('500px', 1, urls, function(oauthBinding) { | |
var identity = oauthBinding.get('https://api.500px.com/v1/users').data; | |
var serviceData = { | |
id: identity.user.id, | |
name: identity.user.username, | |
accessToken: OAuth.sealSecret(oauthBinding.accessToken), | |
accessTokenSecret: OAuth.sealSecret(oauthBinding.accessTokenSecret) | |
}; | |
var profile = identity.user; | |
var fields = _.pick(identity, _500px.whitelistedFields); | |
_.extend(serviceData, fields); | |
return { | |
serviceData: serviceData, | |
options: { | |
profile: profile | |
} | |
}; | |
}); | |
_500px.retrieveCredential = function(credentialToken, credentialSecret) { | |
return OAuth.retrieveCredential(credentialToken, credentialSecret); | |
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Package.describe({ | |
name: 'illuminaut:500px', | |
version: '0.1.1', | |
summary: 'An implementation of the 500px OAuth flow.', | |
git: 'https://github.com/illuminaut/500px.git', | |
documentation: 'README.md' | |
}); | |
Package.onUse(function(api) { | |
api.versionsFrom('1.0.3.1'); | |
api.use('http', ['client', 'server']); | |
api.use('templating', 'client'); | |
api.use('oauth1', ['client', 'server']); | |
api.use('oauth', ['client', 'server']); | |
api.use('random', 'client'); | |
api.use('underscore', 'server'); | |
api.use('service-configuration', ['client', 'server']); | |
api.addFiles(['500px_configure.html', '500px_configure.js'], 'client'); | |
api.addFiles('500px_server.js', 'server'); | |
api.addFiles('500px_client.js', 'client'); | |
api.export('500px'); | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment