Skip to content

Commit

Permalink
flattr.auth_url
Browse files Browse the repository at this point in the history
  • Loading branch information
Michel Legnered committed Jun 10, 2012
1 parent 54f61fe commit 161ef6f
Show file tree
Hide file tree
Showing 4 changed files with 30 additions and 13 deletions.
20 changes: 13 additions & 7 deletions README.md
Expand Up @@ -20,28 +20,34 @@ Require the flattr module:


var flattr = require('flattr'); var flattr = require('flattr');


List an authenticated users flattrs: Authentication code and Token


// First get your auth code by visiting: // First get your auth code by visiting:
// https://flattr.com/oauth/authorize?response_type=code&client_id=<app_key> // https://flattr.com/oauth/authorize?response_type=code&client_id=<app_key>
// // A helper is available to generate the url (with scopes):
// var url = flattr.auth_url(client_id, 'flattr thing email extendedread');

var app = { var app = {
client_id: '<app_key>', client_id: '<app_key>',
client_secret: '<app_secret>', client_secret: '<app_secret>',
// Must match your apps callback url: // Must match your apps callback url:
redirect_uri: 'http://localhost:8080/flattr' redirect_uri: 'http://localhost:8080/flattr'
}; };


flattr.request_token(app, code, function (token) { // Get the token.
flattr.flattrs.list_auth(token, function (flattrs_list) { flattr.request_token(app, auth_code, function (token) {
// do something console.log(token);
});
}); });

List an authenticated users flattrs:
flattr.flattrs.list_auth(token, function (flattrs_list) {
console.log(flattrs_list);
});


List a users (flattr) three latest flattrs: List a users (flattr) three latest flattrs:


flattr.flattrs.list('flattr', {count: 3}, function (flattrs) { flattr.flattrs.list('flattr', {count: 3}, function (flattrs) {
// do something console.log(flattrs);
}); });


# API # API
Expand Down
14 changes: 13 additions & 1 deletion flattr.js
Expand Up @@ -15,7 +15,19 @@ module.exports.flattrs = new Flattrs();
module.exports.things = new Things(); module.exports.things = new Things();
module.exports.users = new Users(); module.exports.users = new Users();


// Requst an access token for authorized requests // Get authentication url
//
// client_id
// scope - Separate several scopes with spaces: "flattr thing email extendedread"
// [res_type] - Response type, code (default) or token
//
exports.auth_url = function (client_id, scope, res_type) {
var res_type = typeof res_type === 'undefined' ? 'code' : res_type;

return url = 'https://flattr.com/oauth/authorize?response_type='+res_type+'&client_id='+client_id+'&scope='+encodeURIComponent(scope);
}

// Request an access token for authorized requests
// //
// app - object containing application data // app - object containing application data
// client_id // client_id
Expand Down
2 changes: 1 addition & 1 deletion package.json
Expand Up @@ -2,7 +2,7 @@
"author": "Michel Legnered <michel.legnered@gmail.com> (http://github.com/antics)", "author": "Michel Legnered <michel.legnered@gmail.com> (http://github.com/antics)",
"name": "flattr", "name": "flattr",
"description": "Module for communicating with the Flattr API.", "description": "Module for communicating with the Flattr API.",
"version": "0.7.2", "version": "0.7.3",
"repository": { "repository": {
"type": "git", "type": "git",
"url": "git://github.com/antics/node-flattr.git" "url": "git://github.com/antics/node-flattr.git"
Expand Down
7 changes: 3 additions & 4 deletions tests/server.js
Expand Up @@ -17,7 +17,7 @@ http.createServer(function (req, res) {
var path = url.parse(req.url).pathname; var path = url.parse(req.url).pathname;


if (path == '/') { if (path == '/') {
res.end('<a href="https://flattr.com/oauth/authorize?response_type=code&client_id='+app.client_id+'&scope=flattr thing extendedread">Login to flattr.</a>'); res.end('<a href="'+flattr.auth_url(app.client_id, 'flattr thing email extendedread')+'">Login to flattr.</a>');
} }
else if (path == '/flattr') { else if (path == '/flattr') {
runtests(req, res); runtests(req, res);
Expand Down Expand Up @@ -66,9 +66,8 @@ function runtests(req, res) {
}); });
}); });
*/
// //
// NOTE: This will flattr node-flattr and draw funds from your account // NOTE: This will flattr and draw funds from your account
// //
var params = { var params = {
title: 'Michels Vaktmästarservice', title: 'Michels Vaktmästarservice',
Expand All @@ -81,7 +80,7 @@ function runtests(req, res) {
status: data.error ? true : false status: data.error ? true : false
}); });
}); });
/*
flattr.things.list('flattr', {count: 10}, function (data) { flattr.things.list('flattr', {count: 10}, function (data) {
done(res, { done(res, {
resource: 'things.list', resource: 'things.list',
Expand Down

0 comments on commit 161ef6f

Please sign in to comment.