Advertisement
Guest User

Untitled

a guest
Oct 25th, 2014
225
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.50 KB | None | 0 0
  1. // Open Bank Project
  2.  
  3. // Copyright 2011,2014 TESOBE / Music Pictures Ltd.
  4.  
  5. // Licensed under the Apache License, Version 2.0 (the "License");
  6. // you may not use this file except in compliance with the License.
  7. // You may obtain a copy of the License at
  8.  
  9. // http://www.apache.org/licenses/LICENSE-2.0
  10.  
  11. // Unless required by applicable law or agreed to in writing, software
  12. // distributed under the License is distributed on an "AS IS" BASIS,
  13. // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  14. // See the License for the specific language governing permissions and
  15. // limitations under the License.
  16.  
  17. // Open Bank Project (http://www.openbankproject.com)
  18. // Copyright 2011,2014 TESOBE / Music Pictures Ltd
  19.  
  20. // This product includes software developed at
  21. // TESOBE (http://www.tesobe.com/)
  22. // by
  23. // TESOBE: contact AT tesobe DOT com
  24. // Nina GΓ€nsdorfer: nina AT tesobe DOT com
  25.  
  26. var express = require('express');
  27. var util = require('util');
  28. var oauth = require('oauth');
  29.  
  30. var app = express();
  31.  
  32.  
  33. // To get the values for the following fields, please register your client here:
  34. // https://apisandbox.openbankproject.com/consumer-registration
  35. var _openbankConsumerKey = "qx1bbxifibosfw1wh2214gpmh3wdac53io5zrraz";
  36. var _openbankConsumerSecret = "wy3k2d0cd1qx5mn2sge5irwzmtxggnjzok1f3umk";
  37.  
  38. var consumer = new oauth.OAuth(
  39. 'https://api.openbankproject.com/oauth/initiate',
  40. 'https://api.openbankproject.com/oauth/token',
  41. _openbankConsumerKey,
  42. _openbankConsumerSecret,
  43. '1.0',
  44. 'http://127.0.0.1:8080/callback',
  45. 'HMAC-SHA1');
  46.  
  47. app.configure(function(){
  48. app.use(express.cookieParser());
  49. app.use(express.session({ secret: "very secret" }));
  50. });
  51.  
  52.  
  53. app.get('/connect', function(req, res){
  54. consumer.getOAuthRequestToken(function(error, oauthToken, oauthTokenSecret, results){
  55. if (error) {
  56. res.send("Error getting OAuth request token : " + util.inspect(error), 500);
  57. } else {
  58. req.session.oauthRequestToken = oauthToken;
  59. req.session.oauthRequestTokenSecret = oauthTokenSecret;
  60. res.redirect("https://api.openbankproject.com/oauth/authorize?oauth_token="+req.session.oauthRequestToken);
  61. console.log("now");
  62. //document.getElementsByClassName("username").value = "filip.ter@gmail.com";
  63. //document.getElementsByClassName("password").value = "12341234";
  64. }
  65. });
  66. });
  67.  
  68.  
  69. app.get('/callback', function(req, res){
  70. console.log("get access token");
  71. consumer.getOAuthAccessToken(req.session.oauthRequestToken, req.session.oauthRequestTokenSecret, req.query.oauth_verifier, function(error, oauthAccessToken, oauthAccessTokenSecret, results) {
  72. if (error) {
  73. res.send("Error getting OAuth access token : " + util.inspect(error) + "["+oauthAccessToken+"]"+ "["+oauthAccessTokenSecret+"]"+ "["+util.inspect(results)+"]", 500);
  74. } else {
  75. req.session.oauthAccessToken = oauthAccessToken;
  76. req.session.oauthAccessTokenSecret = oauthAccessTokenSecret;
  77. res.redirect('/getBanks');
  78. }
  79. });
  80. });
  81.  
  82. app.get('/getBanks', function(req, res){
  83. consumer.get("https://api.openbankproject.com/obp/v1.3.0/banks",
  84. req.session.oauthAccessToken,
  85. req.session.oauthAccessTokenSecret,
  86. function (error, data, response) {
  87. var parsedData = JSON.parse(data);
  88. res.send(parsedData)
  89. });
  90. });
  91.  
  92.  
  93. app.get('*', function(req, res){
  94. res.redirect('/connect');
  95. });
  96.  
  97. app.listen(8080);
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement