authify-api 0.3.0 → 0.3.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: 3fca257750d3b6838d69bf82accc2509efedec36
4
- data.tar.gz: 3e7bffd8e96c2eaa0fac52f0f7cbc7511e0d8a4d
3
+ metadata.gz: 7722ad1f79781ba027cff0bfc6f174d194fb24de
4
+ data.tar.gz: bf8817c6c7b784ee76cfe3e4665540fc3e3b59eb
5
5
  SHA512:
6
- metadata.gz: 0f6224388bec7ae3b38a11c3447950ef5bec48b9505aaade543c9cd517cb643897189bfc077df39fc19a103ab13276b7edb53756981a800b95a4d3b0d43875fe
7
- data.tar.gz: 1169b5cd8efe0660d3ff7fbf533e1dd086dcea7bc30e7824fadcd80dfeeab3c5daff5267b8a669a1ccbcb1077c2763bc59006539c2cdabcecc8e6cd198b2b69f
6
+ metadata.gz: 7aec0faa2c66766a5f3b2570a52198598ee9ab42605581f964841531637954ab69ee255e2fe85747227b7a9c8fc9fbe15bc6c12b8ad91579670098089142ea83
7
+ data.tar.gz: faddeefb5815e21c5c7d991f123ab1f71cb802792183fdf2af43f135d82b1e7b1f25e0143703d000fbe5fdc21d7e898eb3bd36279fcfb4adc4c2e56e8c4fd248
data/README.md CHANGED
@@ -21,7 +21,7 @@ Nearly all API endpoints available via Authify implement the [{json:api}](http:/
21
21
 
22
22
  * `GET /jwt/key` - Returns Content Type: `application/json`. This endpoint returns a JSON Object with the key `data` whose value is a PEM-encoded ECDSA public key, which should be used to verify the signature made by the Authify service.
23
23
  * `GET /jwt/meta` - Returns Content Type: `application/json`. This endpoint returns a JSON Object with the keys `algorithm`, `issuer`, and `expiration` that describe the kind of JWTs produced by this service.
24
- * `POST /jwt/token` - Returns (and only accepts) Content Type: `application/json`. This endpoint is used to obtain a [JWT](https://en.wikipedia.org/wiki/JSON_Web_Token). This endpoint expects a JSON Object with either the keys `access_key` and `secret_key` _OR_ `email` and `password`. There is no firm requirement to use either pair for any particular purpose, but for scenarios where the credentials may be stored, the `access_key` and `secret_key` may be used since those can easily be revoked if necessary. Upon successful authentication, the endpoint provides a JSON Object with the key `jwt` and a signed JWT. There should be nothing highly sensitive embedded in the JWT. The JWT defaults to expiring every 15 minutes.
24
+ * `POST /jwt/token` - Returns (and only accepts) Content Type: `application/json`. This endpoint is used to obtain a [JWT](https://en.wikipedia.org/wiki/JSON_Web_Token). This endpoint expects a JSON Object with either the keys `access_key` and `secret_key` _OR_ `email` and `password`. There is no firm requirement to use either pair for any particular purpose, but for scenarios where the credentials may be stored, the `access_key` and `secret_key` may be used since those can easily be revoked if necessary. Upon successful authentication, the endpoint provides a JSON Object with the key `jwt` and a signed JWT. There should be nothing highly sensitive embedded in the JWT. The JWT defaults to expiring every 15 minutes. This endpoint also allows optionally specifying a key called `inject` with a JSON object as a value. This JSON object will then be injected into a top-level `custom` key in the returned JWT _as is_.
25
25
  * `POST /registration/signup` - Returns (and only accepts) Content Type: `application/json`. This endpoint is used to signup for an account with Authify. This endpoint expects a JSON Object, requiring the keys `email` and `password`, with `name` and `via` being optional. If `via` is provided, then it must be a JSON Object with the keys `provider` and `uid`, otherwise it will be ignored. The `via` key is used to add an alternate identity (meaning they logged-in through an integration, like Github), and is only trusted from trusted delegates (meaning it will be ignored for anonymous calls to this endpoint). This endpoint returns a JSON Object with the keys `id`, `email`, and `verified`, on success. If the user is registered by a trusted delegate *and* `via` options were provided, the users is implicitly trusted and a `jwt` key will also be provided for authentication.
26
26
  * `POST /registration/verify` - Returns (and only accepts) Content Type: `application/json`. This endpoint is used to verify a registered user's email address. This endpoint expects a JSON Object, requiring the keys `email`, `password`, and `token`. This endpoint returns a JSON Object with the keys `id`, `email`, `verified`, and `jwt` on success.
27
27
  * `POST /registration/forgot_password` - Returns (and only accepts) Content Type: `application/json`. This endpoint serves two related purposes: it is used to trigger resetting a forgotten (or non-existent) password and it is used to actually set the value of a user's password. The difference in which operation is performed is based on the POST data. When provided a JSON Object with only the key `email`, the endpoint sends the user an email with a verification token, returning an empty JSON Object as a result. When provided a JSON Object with the keys `email`, `password`, and `token`, the endpoint verifies that the token matches, then sets the user's password, returning a JSON Object with the keys `id`, `email`, `verified`, and `jwt` on success.
@@ -226,6 +226,25 @@ The server will return something like:
226
226
  {"jwt":"eyJ0eXAiOiJKV1QiLCJhbGciOiJFUzUxMiJ9.eyJleHAiOjE0ODY0ODcyODcsImlhdCI6MTQ4NjQ4MzY4NywiaXNzIjoiTXkgQXdlc29tZSBDb21wYW55IEluYy4iLCJzY29wZXMiOlsidXNlcl9hY2Nlc3MiXSwidXNlciI6eyJ1c2VybmFtZSI6ImZvb0BiYXIuY29tIiwidWlkIjoyLCJvcmdhbml6YXRpb25zIjpbXSwiZ3JvdXBzIjpbXX19.AWfPpKX9mP03Djz3-LMneJdEVsXQm_4GOPVCdkfiiBeIR4pVLKTVrNoNdlNgSEkZEeUw1RPsVxpAR7wDgB4cNcYiAP3fNaD8OPyWfOQAV0lTvDUSH3YU39cZAVwvbX9HleOHBLrFGBbui5wSvfi7WZZlH808psiuUAVhBOe7mfrNiHGB"}
227
227
  ```
228
228
 
229
+ You can also request that the server inject some custom payload data into the JWT:
230
+
231
+ ```shell
232
+ curl \
233
+ -H 'Accept: application/json' \
234
+ -H 'Content-Type: application/json' \
235
+ --data \
236
+ '{
237
+ "access_key": "5f4abd1c6423ef02d1ec42e1cddaf5f8",
238
+ "secret_key": "fb97aa7d4e48f3e4bbb2930161a423fa8308393426c3612940da03f22cf36879",
239
+ "inject": {
240
+ "foo": "bar"
241
+ }
242
+ }' \
243
+ https://auth.mycompany.com/jwt/token
244
+ ```
245
+
246
+ This can be useful for loosely coupling services that need to exchange small amounts of (preferably encrypted) data. This data is arbitrary and Authify does nothing to validate it. It simply injects it into the payload before it is signed, so don't assume nefarious users can't spoof things. You'll likely need to do something to make the data verifiable on the receiving end.
247
+
229
248
  #### Use the JWT to Access a Protected Resource
230
249
 
231
250
  ```shell
@@ -5,13 +5,13 @@ module Authify
5
5
  module JWTEncryption
6
6
  include Core::Helpers::JWTSSL
7
7
 
8
- def jwt_token(user = nil)
8
+ def jwt_token(user: nil, custom_data: {})
9
9
  user ||= current_user
10
- JWT.encode jwt_payload(user), private_key, CONFIG[:jwt][:algorithm]
10
+ JWT.encode jwt_payload(user, custom_data), private_key, CONFIG[:jwt][:algorithm]
11
11
  end
12
12
 
13
- def jwt_payload(user)
14
- {
13
+ def jwt_payload(user, custom_data)
14
+ data = {
15
15
  exp: Time.now.to_i + 60 * CONFIG[:jwt][:expiration].to_i,
16
16
  iat: Time.now.to_i,
17
17
  iss: CONFIG[:jwt][:issuer],
@@ -24,6 +24,8 @@ module Authify
24
24
  organizations: simple_orgs_by_user(user)
25
25
  }
26
26
  }
27
+ data[:custom] = custom_data if custom_data && !custom_data.empty?
28
+ data
27
29
  end
28
30
 
29
31
  def simple_orgs_by_user(user)
@@ -38,6 +38,8 @@ module Authify
38
38
  # For Trusted Delegates signing users in via omniauth
39
39
  omni_provider = @parsed_body[:provider]
40
40
  omni_uid = @parsed_body[:uid]
41
+ # Allows injecting custom payload data
42
+ custom_data = @parsed_body[:inject] || {}
41
43
 
42
44
  found_user = if access
43
45
  Models::User.from_api_key(access, secret)
@@ -49,7 +51,7 @@ module Authify
49
51
 
50
52
  if found_user
51
53
  update_current_user found_user
52
- { jwt: jwt_token }.to_json
54
+ { jwt: jwt_token(custom_data: custom_data) }.to_json
53
55
  else
54
56
  halt 401
55
57
  end
@@ -56,7 +56,7 @@ module Authify
56
56
  response = { id: new_user.id, email: new_user.email }
57
57
  if new_user.verified?
58
58
  response[:verified] = true
59
- response[:jwt] = jwt_token(new_user)
59
+ response[:jwt] = jwt_token(user: new_user)
60
60
  else
61
61
  response[:verified] = false
62
62
  end
@@ -78,7 +78,7 @@ module Authify
78
78
  id: found_user.id,
79
79
  email: found_user.email,
80
80
  verified: found_user.verified?,
81
- jwt: jwt_token(found_user)
81
+ jwt: jwt_token(user: found_user)
82
82
  }.to_json
83
83
  else
84
84
  found_user.verified = false
@@ -109,7 +109,7 @@ module Authify
109
109
  id: found_user.id,
110
110
  email: found_user.email,
111
111
  verified: found_user.verified?,
112
- jwt: jwt_token(found_user)
112
+ jwt: jwt_token(user: found_user)
113
113
  }.to_json
114
114
  end
115
115
  end
@@ -3,7 +3,7 @@ module Authify
3
3
  VERSION = [
4
4
  0, # Major
5
5
  3, # Minor
6
- 0 # Patch
6
+ 1 # Patch
7
7
  ].join('.')
8
8
  end
9
9
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: authify-api
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.3.0
4
+ version: 0.3.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Jonathan Gnagy
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2017-04-22 00:00:00.000000000 Z
11
+ date: 2017-05-11 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: authify-core