fidor_starter_kits 0.1.3 → 0.2.0

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: cdb8b69552898f7064d5809486b5d0626e1692ea
4
- data.tar.gz: 4edd4bda246051c1195cb7e2b78a542d8544117d
3
+ metadata.gz: cadf95388bb8c66509a1fe4bb7f97a602ed97336
4
+ data.tar.gz: eba96a1ff9e37cc594a8515464b597e0d9f00eea
5
5
  SHA512:
6
- metadata.gz: 112725ce81cb35fae7d13355e54ac09125cd1e2fd98991e75bb8a4337a15f747f95ba03ab3edfd7154205749920e57fc834dfa195322483953b97fe5cfa2235b
7
- data.tar.gz: 87c863028b83ffd22097bfbd3303caa96611eb3e89cf875f64331340024216f8ef772b03ffca6025e6fd0b7c0061dce133587fd36e672c1fddc206dd5b4b3224
6
+ metadata.gz: 0c74727119b8ec44167a91fcbebd587931d124ee2b5754ce8559f6059077f059277e35eeaf2a990e0fd929b8bee84bedc984473e4a1a764bdc5d5781f5a3aa23
7
+ data.tar.gz: 524b14ea5fee55c16565133a04cd848134bba62c966a4be79261acb3f05cce3a1c69925e1cbd069e9670883f9cc9868f48734728a051faa8c6c10d96c9e320b1
data/README.md CHANGED
@@ -3,7 +3,7 @@
3
3
  This repo features fidor application examples. The apps use oAuth to
4
4
  authenticate with fidor, so you must register an app at fidor first to get your
5
5
  personal app credentials.
6
- Afterwards just copy on of the /starter_kits, add your app credentials to the
6
+ Afterwards just copy one of the /starter_kits, add your app credentials to the
7
7
  example source and start to play.
8
8
 
9
9
  For Ruby Heros, this repo is also available as ruby gem and provides a tiny
@@ -1,3 +1,3 @@
1
1
  module FidorStarterKits
2
- VERSION = '0.1.3'
2
+ VERSION = '0.2.0'
3
3
  end
@@ -2,6 +2,7 @@ require 'fidor_starter_kits/version'
2
2
  require 'fileutils'
3
3
  require 'tmpdir'
4
4
  require 'zip'
5
+ require 'json'
5
6
 
6
7
  module FidorStarterKits
7
8
 
@@ -31,7 +32,7 @@ module FidorStarterKits
31
32
  # @return [Nil | String] path to zipped example im /tmp folder or nil if app does not exists
32
33
  def build(opts)
33
34
  app_name = opts[:app_name]
34
- return if !app_name || !exists?(app_name) || !app_name.in?(STARTER_KITS)
35
+ return if !app_name || !exists?(app_name) || !(STARTER_KITS).include?(app_name)
35
36
 
36
37
  # move example to a safe location
37
38
  example_src_path = File.join(path, app_name)
@@ -59,5 +60,29 @@ module FidorStarterKits
59
60
  zip_file_path
60
61
  end
61
62
 
63
+ def all
64
+ @conf ||= {}
65
+ return @conf unless @conf.length == 0
66
+
67
+ STARTER_KITS.each do |kit|
68
+ base = File.join(path, kit)
69
+ meta = File.join(base, ".fidor_meta.json")
70
+ if File.exists? meta
71
+ File.open(meta) {|f| @conf[kit] = JSON.parse(f.read)}
72
+ else
73
+ @conf[kit] = "meh"
74
+ end
75
+ end
76
+ return @conf
77
+ end
78
+
79
+ def get app_name
80
+ all[app_name]
81
+ end
82
+
83
+ def each
84
+ all.each_value { |conf| yield conf }
85
+ end
86
+
62
87
  end
63
88
  end
@@ -48,4 +48,20 @@ describe FidorStarterKits do
48
48
  expect( content ).to include 'fidor-oauth-url'
49
49
  end
50
50
  end
51
- end
51
+
52
+ describe '.all' do
53
+ it 'lists all starter kits' do
54
+ expect(FidorStarterKits.all.count).to eq(FidorStarterKits::STARTER_KITS.size)
55
+ end
56
+
57
+ it 'loads the json meta data' do
58
+ conf = FidorStarterKits.all
59
+ expect(conf["golang_plain"]["display_name"]).to eq("Go Plain")
60
+ expect(conf["node_tx"]["description"]).to eq("A simple nodejs based app, showing how to get user transactions")
61
+ expect(conf["php_plain"]["app_name"]).to eq("php_plain")
62
+ expect(conf["sinatra_plain"]["app_url"]).to eq("http://localhost:4567")
63
+ expect(conf["java_servlet"]["callback_urls"]).to eq("http://localhost:8080/JavaServlet/Example")
64
+ end
65
+ end
66
+
67
+ end
@@ -0,0 +1,7 @@
1
+ {
2
+ "display_name" : "Go Plain",
3
+ "description" : "A simple Go based app, showing how to get the access token",
4
+ "app_name":"golang_plain",
5
+ "app_url":"http://localhost:8080",
6
+ "callback_urls":"http://localhost:8080"
7
+ }
@@ -0,0 +1,27 @@
1
+ # Basic Go Example
2
+
3
+ This is a basic example project that demonstrates the Fidor API OAuth
4
+ flow. It provides the same functionality as the php example if you would
5
+ like to compare the two sample projects.
6
+
7
+ ## Usage
8
+
9
+ In order to run the example you'll need a Go environment installed (see
10
+ www.golang.org) and can start the sample with:
11
+
12
+ go run example.go
13
+
14
+ The server will listen on port 8080, you can access the example in your
15
+ browser under the following URL:
16
+
17
+ http://localhost:8080
18
+
19
+ ## Configuration
20
+
21
+ In case you downloaded this project from the Fidor AppManager, all the
22
+ configuration should have already been set up for you. In case you
23
+ retrieved this example from another source, you'll need to open the
24
+ `example.go` file and fill in the configuration values at the top of the
25
+ file. You will be able to find out the values in the AppManager, create
26
+ a new App and use the configuration from the new App's detail page.
27
+
@@ -1,21 +1,168 @@
1
+ package main
2
+
3
+ // This is a basic example to illustrate how to access the Fidor API
4
+ // using Go.
5
+ //
6
+ // To run this example type:
7
+ //
8
+ // $ go run example.go
9
+ //
10
+ // And point your browser to:
11
+ //
12
+ // $ http://localhost:8080
13
+
1
14
  import (
15
+ "encoding/json"
2
16
  "fmt"
3
- "io/ioutil"
4
17
  "net/http"
18
+ "net/url"
5
19
  )
6
20
 
21
+ // The following sections define the settings you require for the
22
+ // app to be able to connect to and authorize itself against the api.
23
+
24
+ // app ID and secret, can be found in this apps "Details" page in the
25
+ // AppManager.
26
+ var client_id = "<CLIENT_ID>"
27
+ var client_secret = "<CLIENT_SECRET>"
28
+
29
+ // Fidor's OAuth Endpoint (this changes between Sandbox and Production)
30
+ var fidor_oauth_url = "<FIDOR_OAUTH_URL>" // e.g https://fidor.com/api_sandbox/oauth
31
+ // The OAuth Endpoint this App provides
32
+ var oauth_cb_url = "<APP_URL>"
33
+
34
+ // The URL of the Fidor API (this changes between Sandbox and
35
+ // Production)
36
+ var fidor_api_url = "<FIDOR_API_URL>" // e.g https://fidor.com/api_sandbox vs /api
37
+
38
+
39
+
7
40
 
8
41
  func main() {
9
- http.HandleFunc("/", viewHandler)
10
- http.ListenAndServe(":8080", nil)
42
+ // register a handler function (see next function) to service
43
+ // requests ...
44
+ http.HandleFunc("/", indexHandler)
45
+ // ... and start listening.
46
+ http.ListenAndServe(":8080", nil)
47
+ }
48
+
49
+ func indexHandler(w http.ResponseWriter, r *http.Request) {
50
+
51
+ // ignore any favicon requests, etc.
52
+ if r.URL.Path != "/" {
53
+ w.WriteHeader(404)
54
+ return
55
+ }
56
+
57
+ // check whether we have a GET parameter named `code`, if so,
58
+ // this is a redirect back from the Fidor OAuth server.
59
+ values := r.URL.Query()
60
+ if values["code"] != nil {
61
+ // retrieve the actual OAuth access token ....
62
+ code := values.Get("code")
63
+ if token, err := retrieveTokenFromCode(code); err != nil {
64
+ fmt.Printf("err: %v\n", err)
65
+ w.WriteHeader(500)
66
+ fmt.Fprintf(w, "Unfortunately, an error occured retrieving oauth token")
67
+ } else {
68
+ // ... and finally, greet the user and assemble links
69
+ renderWelcome(w, token)
70
+ }
71
+ } else {
72
+ // we don't have an oauth `code` yet, so we need to
73
+ // redirect the user to the OAuth provider to get one ...
74
+ oauth_url := fmt.Sprintf("%s/authorize?client_id=%s&redirect_uri=%s",
75
+ fidor_oauth_url,
76
+ client_id,
77
+ url.QueryEscape(oauth_cb_url))
78
+
79
+ header := w.Header()
80
+ header.Add("location", oauth_url)
81
+ w.WriteHeader(307)
82
+ }
83
+ }
84
+
85
+
86
+ // Our TokenResponse representation used to pick it out from the JSON
87
+ // returned by the OAuth server.
88
+ type TokenResponse struct {
89
+ Token string `json:"access_token"`
90
+ }
91
+
92
+ // Use the OAuth code that the user's browser picked up from the OAuth
93
+ // server to request an OAuth access_token to use in API requests.
94
+ func retrieveTokenFromCode(code string) (token string, err error) {
95
+ // assemble the API endpoint URL and request payload
96
+ tokenUrl := fmt.Sprintf("%s/token", fidor_oauth_url)
97
+ tokenPayload := url.Values{
98
+ "client_id": {client_id},
99
+ "client_secret": {client_secret},
100
+ "code": {code},
101
+ }
102
+ // Call API
103
+ if resp, err := http.PostForm(tokenUrl, tokenPayload); err != nil {
104
+ return "", err
105
+ } else {
106
+ // if successful, pick the access_token out of the reply.
107
+ var tokenResponse TokenResponse
108
+ decoder := json.NewDecoder(resp.Body)
109
+ if err = decoder.Decode(&tokenResponse); err != nil {
110
+ return "", err
111
+ } else {
112
+ return tokenResponse.Token, nil
113
+ }
114
+ }
11
115
  }
12
116
 
13
- func viewHandler(w http.ResponseWriter, r *http.Request) {
14
117
 
15
- app_url := "<APP-URL>" //default: http://localhost:8080
16
- client_id := "<CLIENT-ID>"
17
- client_secret := "<CLIENT-SECRET>"
18
- fidor_url := "<FIDOR-URL>"
118
+ // Our server code only makes a single call to the API to retrieve user
119
+ // information. This is our internal representation of the returned JSON
120
+ // used to pick out the user's email.
121
+ type UserResponse struct {
122
+ Email string `json:"email"`
123
+ }
124
+
125
+ // function to retreive user information from the API
126
+ func getUser(token string) (u UserResponse, err error) {
127
+ // Assemble endpoint URL...
128
+ url := fmt.Sprintf("%s/users/current?access_token=%s", fidor_api_url, token)
129
+ if resp, err := http.Get(url); err != nil {
130
+ return u, err
131
+ } else {
132
+ decoder := json.NewDecoder(resp.Body)
133
+ if err = decoder.Decode(&u); err != nil {
134
+ return u, err
135
+ } else {
136
+ return u, nil
137
+ }
138
+ }
139
+ }
19
140
 
20
- fmt.Fprintf(w, "<h1>You made it!</h1><div>%s</div>", p)
141
+
142
+ // once all the OAuth calls have been taken care of, this function is
143
+ // called from the http handler. It retrieves the user's email address
144
+ // and inserts links to `transaction` and `accounts` endpoints.
145
+
146
+ func renderWelcome(w http.ResponseWriter, token string) {
147
+ if user, err := getUser(token); err != nil {
148
+ fmt.Printf("err: %v\n", err)
149
+ w.WriteHeader(500)
150
+ } else {
151
+ txLink := fmt.Sprintf("%s/transactions?access_token=%s", fidor_api_url, token)
152
+ acctsLink := fmt.Sprintf("%s/accounts?access_token=%s", fidor_api_url, token)
153
+ fmt.Fprintf(w, indexTemplate, user.Email, token, txLink, acctsLink)
154
+ }
21
155
  }
156
+
157
+ var indexTemplate = `
158
+ <html>
159
+ <head>
160
+ </head>
161
+ <body>
162
+ <h1>Welcome %s!</h1>
163
+ <i>retrieved <tt>access_token</tt>: %s</i>
164
+ <p><a href="%s">Transactions</a></p>
165
+ <p><a href="%s">Accounts</a></p>
166
+ </body>
167
+ </html>
168
+ `
@@ -0,0 +1,7 @@
1
+ {
2
+ "display_name" : "Java Servlet Plain",
3
+ "description" : "A simple java servlet based app, showing how to get the access token",
4
+ "app_name":"java_servlet",
5
+ "app_url":"http://localhost:8080/JavaServlet/Example",
6
+ "callback_urls":"http://localhost:8080/JavaServlet/Example"
7
+ }
@@ -0,0 +1,7 @@
1
+ {
2
+ "display_name" : "Node Transactions",
3
+ "description" : "A simple nodejs based app, showing how to get user transactions",
4
+ "app_name":"node_tx",
5
+ "app_url":"http://localhost:3001",
6
+ "callback_urls":"http://localhost:3001/code"
7
+ }
@@ -0,0 +1,7 @@
1
+ {
2
+ "display_name" : "PHP Plain",
3
+ "description" : "A simple php script, showing how to get the access token",
4
+ "app_name":"php_plain",
5
+ "app_url":"http://localhost:8000/example.php",
6
+ "callback_urls":"http://localhost:8080/example.php"
7
+ }
@@ -1,6 +1,7 @@
1
1
  # Plain PHP Login - Example
2
2
 
3
- A single view showing how to get an access token
3
+ A single view that demonstrates the Fidor API OAuth login flow and how to get
4
+ an access token.
4
5
 
5
6
  ## Usage
6
7
 
@@ -11,4 +12,14 @@ Start your local php server:
11
12
  And point your browser to http://localhost:8000/example.php
12
13
 
13
14
  If you run the example under a different url, please update the url in the
14
- source file
15
+ source file
16
+
17
+
18
+ ## Configuration
19
+
20
+ In case you downloaded this project from the Fidor AppManager, all the
21
+ configuration should have already been set up for you. In case you
22
+ retrieved this example from another source, you'll need to open the
23
+ `example.php` file and fill in the configuration values at the top of the
24
+ file. You will be able to find out the values in the AppManager, create
25
+ a new App and use the configuration from the new App's detail page.
@@ -7,6 +7,7 @@
7
7
  $fidor_api_url = "<FIDOR_API_URL>"; # e.g https://fidor.com/api_sandbox vs /api
8
8
 
9
9
  $code = $_REQUEST["code"];
10
+
10
11
  # 1. redirect to authorize url
11
12
  if(empty($code)) {
12
13
  $dialog_url = $fidor_oauth_url . "/authorize?" .
@@ -40,10 +41,10 @@
40
41
  $user = json_decode(file_get_contents($usr_url));
41
42
  $transactions_url = $fidor_api_url . "/transactions?access_token=" . $resp->access_token;
42
43
  echo( "<h2>Hello " . $user->email . "</h2>
43
- <i>May i present the access token response:</i>
44
+ <i>May I present the access token response:</i>
44
45
  <blockquote>");
45
46
  print_r($resp);
46
47
  echo("</blockquote>
47
- <p>Now use the access token in <br> <a href='" . $transactions_url . "'>".$transactions_url."</a></p>");
48
+ <p>Now use the access token here: <br> <a href='" . $transactions_url . "'>".$transactions_url."</a></p>");
48
49
 
49
- ?>
50
+ ?>
@@ -0,0 +1,7 @@
1
+ {
2
+ "display_name" : "Ruby Sinatra Plain",
3
+ "description" : "A simple Sinatra based app, showing how to get an access token.",
4
+ "app_name":"sinatra_plain",
5
+ "app_url":"http://localhost:4567",
6
+ "callback_urls":"http://localhost:4567"
7
+ }
@@ -1,8 +1,9 @@
1
- = Plain Login - Example
1
+ # Ruby Plain oAuth Login - Example
2
2
 
3
- A single view showing how to get an access token
3
+ A single view that demonstrates the Fidor API OAuth login flow and how to get
4
+ an access token.
4
5
 
5
- == Usage
6
+ ## Usage
6
7
 
7
8
  This uses bundler to install the required gems:
8
9
 
@@ -12,3 +13,12 @@ This uses bundler to install the required gems:
12
13
 
13
14
  # or run on different port than :4567 provided by WEBrick
14
15
  ruby example.rb -p 3004
16
+
17
+ ## Configuration
18
+
19
+ In case you downloaded this project from the Fidor AppManager, all the
20
+ configuration should have already been set up for you. In case you
21
+ retrieved this example from another source, you'll need to open the
22
+ `example.rb` file and fill in the configuration values at the top of the
23
+ file. You will be able to find out the values in the AppManager, create
24
+ a new App and use the configuration from the new App's detail page.
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.1.3
4
+ version: 0.2.0
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-10 00:00:00.000000000 Z
11
+ date: 2014-10-16 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rubyzip
@@ -84,8 +84,11 @@ files:
84
84
  - lib/fidor_starter_kits/version.rb
85
85
  - spec/fidor_starter_kits_spec.rb
86
86
  - spec/spec_helper.rb
87
+ - starter_kits/golang_plain/.fidor_meta.json
88
+ - starter_kits/golang_plain/README.md
87
89
  - starter_kits/golang_plain/example.go
88
90
  - starter_kits/java_servlet/.classpath
91
+ - starter_kits/java_servlet/.fidor_meta.json
89
92
  - starter_kits/java_servlet/.project
90
93
  - starter_kits/java_servlet/.settings/.jsdtscope
91
94
  - starter_kits/java_servlet/.settings/org.eclipse.jdt.core.prefs
@@ -103,9 +106,12 @@ files:
103
106
  - starter_kits/java_servlet/WebContent/WEB-INF/lib/httpmime-4.3.5.jar
104
107
  - starter_kits/java_servlet/WebContent/WEB-INF/lib/json-simple-1.1.1.jar
105
108
  - starter_kits/java_servlet/src/de/fidor/api/example/Example.java
109
+ - starter_kits/node_tx/.fidor_meta.json
106
110
  - starter_kits/node_tx/example.js
111
+ - starter_kits/php_plain/.fidor_meta.json
107
112
  - starter_kits/php_plain/README.md
108
113
  - starter_kits/php_plain/example.php
114
+ - starter_kits/sinatra_plain/.fidor_meta.json
109
115
  - starter_kits/sinatra_plain/Gemfile
110
116
  - starter_kits/sinatra_plain/README.md
111
117
  - starter_kits/sinatra_plain/example.rb