fidor_starter_kits 0.2.0 → 0.2.1

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: cadf95388bb8c66509a1fe4bb7f97a602ed97336
4
- data.tar.gz: eba96a1ff9e37cc594a8515464b597e0d9f00eea
3
+ metadata.gz: a9f36a71cf140528a255f198e3f9bb39b2941f1a
4
+ data.tar.gz: 9d2f59be8b09478bd16b79acd89a1da7387a7795
5
5
  SHA512:
6
- metadata.gz: 0c74727119b8ec44167a91fcbebd587931d124ee2b5754ce8559f6059077f059277e35eeaf2a990e0fd929b8bee84bedc984473e4a1a764bdc5d5781f5a3aa23
7
- data.tar.gz: 524b14ea5fee55c16565133a04cd848134bba62c966a4be79261acb3f05cce3a1c69925e1cbd069e9670883f9cc9868f48734728a051faa8c6c10d96c9e320b1
6
+ metadata.gz: f7f6cce79401c37a005f590e5741bb2b1e52c11482a5daf319e4e7add3ec6ac272ad1e93c113bf750d62960d61011cfe68615c6854a9cfbdea9a42503bf88b22
7
+ data.tar.gz: 12fb81b5b2fcfecc8f69ea9ffa9635f48b4a0e142a17ef8e3d836b20163c72d6d4b04fe73a70d4aa1a957c12b6bda2abccdf0ea145687c296161dfe0b7668867
@@ -1,3 +1,3 @@
1
1
  module FidorStarterKits
2
- VERSION = '0.2.0'
2
+ VERSION = '0.2.1'
3
3
  end
@@ -42,6 +42,7 @@ func main() {
42
42
  // register a handler function (see next function) to service
43
43
  // requests ...
44
44
  http.HandleFunc("/", indexHandler)
45
+ fmt.Printf("Now open http://localhost:8080")
45
46
  // ... and start listening.
46
47
  http.ListenAndServe(":8080", nil)
47
48
  }
@@ -63,7 +64,7 @@ func indexHandler(w http.ResponseWriter, r *http.Request) {
63
64
  if token, err := retrieveTokenFromCode(code); err != nil {
64
65
  fmt.Printf("err: %v\n", err)
65
66
  w.WriteHeader(500)
66
- fmt.Fprintf(w, "Unfortunately, an error occured retrieving oauth token")
67
+ fmt.Fprintf(w, "Unfortunately, an error occurred retrieving oauth token")
67
68
  } else {
68
69
  // ... and finally, greet the user and assemble links
69
70
  renderWelcome(w, token)
@@ -122,7 +123,7 @@ type UserResponse struct {
122
123
  Email string `json:"email"`
123
124
  }
124
125
 
125
- // function to retreive user information from the API
126
+ // function to retrieve user information from the API
126
127
  func getUser(token string) (u UserResponse, err error) {
127
128
  // Assemble endpoint URL...
128
129
  url := fmt.Sprintf("%s/users/current?access_token=%s", fidor_api_url, token)
@@ -2,6 +2,6 @@
2
2
  "display_name" : "Node Transactions",
3
3
  "description" : "A simple nodejs based app, showing how to get user transactions",
4
4
  "app_name":"node_tx",
5
- "app_url":"http://localhost:3001",
6
- "callback_urls":"http://localhost:3001/code"
5
+ "app_url":"http://localhost:3141",
6
+ "callback_urls":"http://localhost:3141/code"
7
7
  }
@@ -15,7 +15,7 @@
15
15
 
16
16
  var fidor_config = {
17
17
  app_port : 3141, // you might want to change this to match your app_url
18
- app_url : "<APP_URL>",
18
+ app_url : "<APP_URL>", // must also include the port e.g http://localhost:3141
19
19
  client_id : "<CLIENT_ID>",
20
20
  client_secret : "<CLIENT_SECRET>",
21
21
  fidor_api_url : "<FIDOR_API_URL>"
@@ -23,20 +23,20 @@ var fidor_config = {
23
23
 
24
24
  // This app can be started by executing:
25
25
  //
26
- // node server.js
26
+ // node example.js
27
27
  //
28
28
  // Once the app is running, it can be accessed on:
29
29
  //
30
- // http://localhost:3001
30
+ // http://localhost:3141
31
31
  //
32
32
  // or on whatever port is configured above.
33
33
  //
34
34
  // The app checks whether an OAuth access token is available for the
35
- // user, if not, the user is redirected to the OAuth endpoit. After
35
+ // user, if not, the user is redirected to the OAuth endpoint. After
36
36
  // successful authentication and authorization, the OAuth endpoint
37
37
  // redirects the user back to the app. Specifically to:
38
38
  //
39
- // http://localhost:3001/code
39
+ // http://localhost:3141/code
40
40
  //
41
41
  // This redirect will contain a query with the OAuth code. The app uses
42
42
  // this code to request an OAuth access-token. The retrieved token is stored with
@@ -56,10 +56,10 @@ function apiGetTransactions(accessToken, cb) {
56
56
  var tx_url = fidor_config.fidor_api_url+
57
57
  "/transactions?access_token="+
58
58
  accessToken
59
-
59
+
60
60
  var get = http.get(tx_url, function(res){
61
- // response may come in numerous chunks, we need to collect
62
- // them and reassemble the entire answer when all data has
61
+ // response may come in numerous chunks, we need to collect
62
+ // them and reassemble the entire answer when all data has
63
63
  // been retrieved.
64
64
  var data = new Buffer(0)
65
65
  res.on('data', function(chunk){
@@ -84,15 +84,15 @@ function apiGetTransactions(accessToken, cb) {
84
84
  // The handle for the Apps /transactions endpoint.
85
85
  // @param request : http request object
86
86
  // @param response : http response
87
- //
87
+ //
88
88
  function getTransactions(request, response) {
89
89
  var cookie_token = getCookie(request, "oauth_token")
90
- // if we don't have a token for this user already, redirect
90
+ // if we don't have a token for this user already, redirect
91
91
  // the user to the OAuth server
92
92
  if (!cookie_token) {
93
- var oauth_url = fidor_config.fidor_api_url+"/oauth/authorize?client_id="+
94
- fidor_config.client_id+"&redirect_uri="+fidor_config.app_url+":"+
95
- fidor_config.app_port+"/code"
93
+ var oauth_url = fidor_config.fidor_api_url+"/oauth/authorize?"+
94
+ "client_id="+fidor_config.client_id+
95
+ "&redirect_uri="+fidor_config.app_url+"/code"
96
96
  response.writeHead(307, {"location" : oauth_url})
97
97
  response.end()
98
98
  return
@@ -100,7 +100,7 @@ function getTransactions(request, response) {
100
100
 
101
101
  // trade in the key we stored in the cookie for the actual oauth token.
102
102
  var oauth_token = getToken(cookie_token)
103
-
103
+
104
104
  // call the api with the OAuth token:
105
105
  apiGetTransactions(oauth_token, function (err, transactions) {
106
106
  if (err) {
@@ -136,7 +136,7 @@ function getOAuthToken(code, cb) {
136
136
  port : oauth_url.port,
137
137
  host : oauth_url.hostname
138
138
  }
139
-
139
+
140
140
  // ... what to send
141
141
  var postData = {
142
142
  code : code,
@@ -144,7 +144,7 @@ function getOAuthToken(code, cb) {
144
144
  client_secret : fidor_config.client_secret
145
145
  }
146
146
  postData = querystring.stringify(postData)
147
-
147
+
148
148
  var token_request = http.request(postOptions, function (res) {
149
149
  // collect the data chunks we received and reassemble them
150
150
  // on request end ...
@@ -167,21 +167,21 @@ function getOAuthToken(code, cb) {
167
167
  token_request.end()
168
168
  }
169
169
 
170
- // handler we provide to handle our user being redirected back
171
- // to us from the OAuth server with the OAuth `code` in the
170
+ // handler we provide to handle our user being redirected back
171
+ // to us from the OAuth server with the OAuth `code` in the
172
172
  // query of the url.
173
173
  function setOAuthToken(request, response) {
174
174
  var u = url.parse(request.url)
175
175
  var code = querystring.parse(u.query)["code"]
176
-
177
- // if the request does not contain a ?code=adsfasdfasdf
176
+
177
+ // if the request does not contain a ?code=adsfasdfasdf
178
178
  // query, it's not valid.
179
179
  if (!code) {
180
180
  response.writeHead(400, "Bad Request")
181
181
  response.end()
182
182
  return
183
183
  }
184
-
184
+
185
185
  // exchange the code for a token ...
186
186
  getOAuthToken(code, function (err, token) {
187
187
  if (err) {
@@ -200,7 +200,7 @@ function setOAuthToken(request, response) {
200
200
  // may need it in the future without leaking the actual access_token
201
201
  // via the cookie
202
202
 
203
- var token_key = storeToken(token)
203
+ var token_key = storeToken(token)
204
204
  setCookie(response, "oauth_token", token_key)
205
205
 
206
206
  // send the user back to the transactions url, this time, with a
@@ -216,10 +216,10 @@ function listener(req, resp) {
216
216
  if (req.method !== "GET") {
217
217
  resp.writeHead(403, "Forbidden")
218
218
  }
219
-
219
+
220
220
  var u = url.parse(req.url)
221
221
  switch (u.pathname) {
222
- case "/":
222
+ case "/":
223
223
  console.log("start page ...")
224
224
  resp.writeHead(200, {"Content-Type" : "text/html"})
225
225
  resp.end(hello_template)
@@ -274,7 +274,7 @@ var hello_template = ""+
274
274
  " <p><a href='/clear_cookie'>Clear Cookie</a></p>" +
275
275
  " <p><a href='/clear_all_cookies'>Clear All Cookies</a></p>" +
276
276
  "</body>" +
277
- "</html>"
277
+ "</html>"
278
278
 
279
279
  // Code for setting and clearing cookies. Typically a framework would
280
280
  // handle the intricacies of cookie handling, but we opted not to
@@ -312,7 +312,7 @@ function getCookies(request) {
312
312
  cookies[c[0].trim()] = c[1]
313
313
  })
314
314
  }
315
- return cookies
315
+ return cookies
316
316
  }
317
317
 
318
318
  function getCookie(request, key) {
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: fidor_starter_kits
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.2.0
4
+ version: 0.2.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Georg Leciejewski
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2014-10-16 00:00:00.000000000 Z
11
+ date: 2014-11-20 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rubyzip