castle-rb 1.0.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/README.md +77 -0
- data/lib/castle.rb +47 -0
- data/lib/castle/client.rb +139 -0
- data/lib/castle/configuration.rb +37 -0
- data/lib/castle/errors.rb +16 -0
- data/lib/castle/ext/her.rb +14 -0
- data/lib/castle/jwt.rb +36 -0
- data/lib/castle/models/account.rb +11 -0
- data/lib/castle/models/backup_codes.rb +4 -0
- data/lib/castle/models/challenge.rb +7 -0
- data/lib/castle/models/context.rb +18 -0
- data/lib/castle/models/event.rb +7 -0
- data/lib/castle/models/model.rb +71 -0
- data/lib/castle/models/monitoring.rb +6 -0
- data/lib/castle/models/pairing.rb +11 -0
- data/lib/castle/models/recommendation.rb +3 -0
- data/lib/castle/models/session.rb +6 -0
- data/lib/castle/models/trusted_device.rb +5 -0
- data/lib/castle/models/user.rb +20 -0
- data/lib/castle/request.rb +164 -0
- data/lib/castle/session_store.rb +35 -0
- data/lib/castle/session_token.rb +39 -0
- data/lib/castle/support/cookie_store.rb +48 -0
- data/lib/castle/support/padrino.rb +19 -0
- data/lib/castle/support/rails.rb +11 -0
- data/lib/castle/support/sinatra.rb +17 -0
- data/lib/castle/token_store.rb +30 -0
- data/lib/castle/utils.rb +22 -0
- data/lib/castle/version.rb +3 -0
- data/spec/fixtures/vcr_cassettes/challenge_create.yml +48 -0
- data/spec/fixtures/vcr_cassettes/challenge_verify.yml +42 -0
- data/spec/fixtures/vcr_cassettes/session_create.yml +47 -0
- data/spec/fixtures/vcr_cassettes/session_refresh.yml +47 -0
- data/spec/fixtures/vcr_cassettes/session_verify.yml +47 -0
- data/spec/fixtures/vcr_cassettes/user_find.yml +44 -0
- data/spec/fixtures/vcr_cassettes/user_find_non_existing.yml +42 -0
- data/spec/fixtures/vcr_cassettes/user_import.yml +46 -0
- data/spec/fixtures/vcr_cassettes/user_update.yml +47 -0
- data/spec/helpers_spec.rb +38 -0
- data/spec/jwt_spec.rb +67 -0
- data/spec/models/challenge_spec.rb +18 -0
- data/spec/models/session_spec.rb +14 -0
- data/spec/models/user_spec.rb +31 -0
- data/spec/spec_helper.rb +29 -0
- data/spec/utils_spec.rb +59 -0
- metadata +273 -0
@@ -0,0 +1,48 @@
|
|
1
|
+
---
|
2
|
+
http_interactions:
|
3
|
+
- request:
|
4
|
+
method: post
|
5
|
+
uri: https://:secretkey@api.castle.io/v1/users/dTxR68nzuRXT4wrB2HJ4hanYtcaGSz2y/challenges
|
6
|
+
body:
|
7
|
+
encoding: UTF-8
|
8
|
+
string: "{}"
|
9
|
+
headers:
|
10
|
+
User-Agent:
|
11
|
+
- Castle/v1 RubyBindings/1.0.4
|
12
|
+
X-Castle-Client-User-Agent:
|
13
|
+
- '{"bindings_version":"1.0.4","lang":"ruby","lang_version":"2.1.1 p76 (2014-02-24)","platform":"x86_64-darwin13.0","publisher":"castle","uname":"Darwin
|
14
|
+
Johans-MacBook-Pro-2.local 13.2.0 Darwin Kernel Version 13.2.0: Thu Apr 17
|
15
|
+
23:03:13 PDT 2014; root:xnu-2422.100.13~1/RELEASE_X86_64 x86_64"}'
|
16
|
+
Content-Type:
|
17
|
+
- application/json
|
18
|
+
Accept-Encoding:
|
19
|
+
- gzip;q=1.0,deflate;q=0.6,identity;q=0.3
|
20
|
+
Accept:
|
21
|
+
- "*/*"
|
22
|
+
response:
|
23
|
+
status:
|
24
|
+
code: 201
|
25
|
+
message: 'Created '
|
26
|
+
headers:
|
27
|
+
Content-Type:
|
28
|
+
- application/json
|
29
|
+
Content-Length:
|
30
|
+
- '476'
|
31
|
+
X-Ua-Compatible:
|
32
|
+
- IE=Edge
|
33
|
+
Etag:
|
34
|
+
- '"ee1750920e2acc320adbd6826d5299be"'
|
35
|
+
Cache-Control:
|
36
|
+
- max-age=0, private, must-revalidate
|
37
|
+
Server:
|
38
|
+
- WEBrick/1.3.1 (Ruby/2.1.1/2014-02-24)
|
39
|
+
Date:
|
40
|
+
- Sat, 07 Jun 2014 20:42:33 GMT
|
41
|
+
Connection:
|
42
|
+
- Keep-Alive
|
43
|
+
body:
|
44
|
+
encoding: UTF-8
|
45
|
+
string: '{"id":"UWwy5FrWf9DTeoTpJz1LpBp4dPkWZ2Ne","created_at":"2014-06-07T20:42:33Z","channel":{"id":"Ff892rfGx3TwNF33sQUz3S51NsV24w7H","created_at":"2014-06-07T20:25:27Z","primary":true,"type":"token","token":{"id":"VVG3qirUxy8mUSkmzy3QpPcuhLN1JY4r","created_at":"2014-06-07T20:24:39Z","verified":true,"qr_url":"https://chart.googleapis.com/chart?chs=200x200&chld=M|0&cht=qr&chl=otpauth%3A%2F%2Ftotp%2FCastle%3Abrissmyr%40gmail.com%3Fsecret%3Dxulnnls324pajcfn%26issuer%3DCastle"}}}'
|
46
|
+
http_version:
|
47
|
+
recorded_at: Sat, 07 Jun 2014 20:42:33 GMT
|
48
|
+
recorded_with: VCR 2.9.0
|
@@ -0,0 +1,42 @@
|
|
1
|
+
---
|
2
|
+
http_interactions:
|
3
|
+
- request:
|
4
|
+
method: post
|
5
|
+
uri: https://:secretkey@api.castle.io/v1/challenges/UWwy5FrWf9DTeoTpJz1LpBp4dPkWZ2Ne/verify
|
6
|
+
body:
|
7
|
+
encoding: UTF-8
|
8
|
+
string: '{"response":"000000"}'
|
9
|
+
headers:
|
10
|
+
User-Agent:
|
11
|
+
- Castle/v1 RubyBindings/1.0.4
|
12
|
+
X-Castle-Client-User-Agent:
|
13
|
+
- '{"bindings_version":"1.0.4","lang":"ruby","lang_version":"2.1.1 p76 (2014-02-24)","platform":"x86_64-darwin13.0","publisher":"castle","uname":"Darwin
|
14
|
+
Johans-MacBook-Pro-2.local 13.2.0 Darwin Kernel Version 13.2.0: Thu Apr 17
|
15
|
+
23:03:13 PDT 2014; root:xnu-2422.100.13~1/RELEASE_X86_64 x86_64"}'
|
16
|
+
Content-Type:
|
17
|
+
- application/json
|
18
|
+
Accept-Encoding:
|
19
|
+
- gzip;q=1.0,deflate;q=0.6,identity;q=0.3
|
20
|
+
Accept:
|
21
|
+
- "*/*"
|
22
|
+
response:
|
23
|
+
status:
|
24
|
+
code: 204
|
25
|
+
message: 'No Content '
|
26
|
+
headers:
|
27
|
+
X-Ua-Compatible:
|
28
|
+
- IE=Edge
|
29
|
+
Cache-Control:
|
30
|
+
- no-cache
|
31
|
+
Server:
|
32
|
+
- WEBrick/1.3.1 (Ruby/2.1.1/2014-02-24)
|
33
|
+
Date:
|
34
|
+
- Sat, 07 Jun 2014 20:52:43 GMT
|
35
|
+
Connection:
|
36
|
+
- Keep-Alive
|
37
|
+
body:
|
38
|
+
encoding: UTF-8
|
39
|
+
string: ''
|
40
|
+
http_version:
|
41
|
+
recorded_at: Sat, 07 Jun 2014 20:52:43 GMT
|
42
|
+
recorded_with: VCR 2.9.0
|
@@ -0,0 +1,47 @@
|
|
1
|
+
---
|
2
|
+
http_interactions:
|
3
|
+
- request:
|
4
|
+
method: post
|
5
|
+
uri: https://:secretkey@api.castle.io/v1/users/user-2412/sessions
|
6
|
+
body:
|
7
|
+
encoding: UTF-8
|
8
|
+
string: '{"user":{"email":"valid@example.com"}}'
|
9
|
+
headers:
|
10
|
+
User-Agent:
|
11
|
+
- Faraday v0.9.0
|
12
|
+
Content-Type:
|
13
|
+
- application/json
|
14
|
+
Accept-Encoding:
|
15
|
+
- gzip;q=1.0,deflate;q=0.6,identity;q=0.3
|
16
|
+
Accept:
|
17
|
+
- "*/*"
|
18
|
+
response:
|
19
|
+
status:
|
20
|
+
code: 201
|
21
|
+
message: 'Created '
|
22
|
+
headers:
|
23
|
+
Content-Type:
|
24
|
+
- application/json
|
25
|
+
Content-Length:
|
26
|
+
- '716'
|
27
|
+
X-Ua-Compatible:
|
28
|
+
- IE=Edge
|
29
|
+
Etag:
|
30
|
+
- '"c323dc2244006efcc5629936b73749ff"'
|
31
|
+
Cache-Control:
|
32
|
+
- max-age=0, private, must-revalidate
|
33
|
+
Server:
|
34
|
+
- WEBrick/1.3.1 (Ruby/2.1.1/2014-02-24)
|
35
|
+
Date:
|
36
|
+
- Wed, 07 May 2014 16:21:05 GMT
|
37
|
+
Connection:
|
38
|
+
- Keep-Alive
|
39
|
+
Set-Cookie:
|
40
|
+
- _ubt=; expires=Thu, 01-Jan-1970 00:00:00 GMT
|
41
|
+
body:
|
42
|
+
encoding: UTF-8
|
43
|
+
string: '{"id":"S2odxReZnGqhqxPaQ7V7kNkLoXkGZPFz","token":"eyJ0eXAiOiJKV1QiLCJhbGciOiJIUzI1NiIsImlzcyI6InVzZXItMjQxMiIsInN1YiI6IlMyb2R4UmVabkdxaHF4UGFRN1Y3a05rTG9Ya0daUEZ6IiwiYXVkIjoiODAwMDAwMDAwMDAwMDAwIiwiZXhwIjoxMzk5NDc5Njc1LCJpYXQiOjEzOTk0Nzk2NjUsImp0aSI6MH0.eyJjaGFsbGVuZ2UiOnsiaWQiOiJUVENqd3VyM3lwbTRUR1ZwWU43cENzTXFxOW9mWEVBSCIsInR5cGUiOiJvdHBfYXV0aGVudGljYXRvciJ9fQ.LT9mUzJEbsizbFxcpMo3zbms0aCDBzfgMbveMGSi1-s","user":{"id":"8Fpmj9asxpq4mwGzx48MP1EQhdWUHDeb","local_id":"user-2412","created_at":"2014-05-07T15:33:58Z","updated_at":"2014-05-07T16:04:56Z","email":"valid@example.com","username":"valid@example.com","name":"New
|
44
|
+
Name","first_name":null,"last_name":null,"image":null,"status":"ACTIVE","mfa_enabled":true}}'
|
45
|
+
http_version:
|
46
|
+
recorded_at: Wed, 07 May 2014 16:21:05 GMT
|
47
|
+
recorded_with: VCR 2.9.0
|
@@ -0,0 +1,47 @@
|
|
1
|
+
---
|
2
|
+
http_interactions:
|
3
|
+
- request:
|
4
|
+
method: post
|
5
|
+
uri: https://:secretkey@api.castle.io/v1/sessions/eyJ0eXAiOiJKV1QiLCJhbGciOiJIUzI1NiIsImlzcyI6InVzZXItMjQxMiIsInN1YiI6IlMyb2R4UmVabkdxaHF4UGFRN1Y3a05rTG9Ya0daUEZ6IiwiYXVkIjoiODAwMDAwMDAwMDAwMDAwIiwiZXhwIjoxMzk5NDc5Njc1LCJpYXQiOjEzOTk0Nzk2NjUsImp0aSI6MH0.eyJjaGFsbGVuZ2UiOnsiaWQiOiJUVENqd3VyM3lwbTRUR1ZwWU43cENzTXFxOW9mWEVBSCIsInR5cGUiOiJvdHBfYXV0aGVudGljYXRvciJ9fQ.LT9mUzJEbsizbFxcpMo3zbms0aCDBzfgMbveMGSi1-s/refresh
|
6
|
+
body:
|
7
|
+
encoding: UTF-8
|
8
|
+
string: '{"user":{"name":"New Name"}}'
|
9
|
+
headers:
|
10
|
+
User-Agent:
|
11
|
+
- Faraday v0.9.0
|
12
|
+
Content-Type:
|
13
|
+
- application/json
|
14
|
+
Accept-Encoding:
|
15
|
+
- gzip;q=1.0,deflate;q=0.6,identity;q=0.3
|
16
|
+
Accept:
|
17
|
+
- "*/*"
|
18
|
+
response:
|
19
|
+
status:
|
20
|
+
code: 201
|
21
|
+
message: 'Created '
|
22
|
+
headers:
|
23
|
+
Content-Type:
|
24
|
+
- application/json
|
25
|
+
Content-Length:
|
26
|
+
- '716'
|
27
|
+
X-Ua-Compatible:
|
28
|
+
- IE=Edge
|
29
|
+
Etag:
|
30
|
+
- '"537ee28e9894002208f8f645f6dd2987"'
|
31
|
+
Cache-Control:
|
32
|
+
- max-age=0, private, must-revalidate
|
33
|
+
Server:
|
34
|
+
- WEBrick/1.3.1 (Ruby/2.1.1/2014-02-24)
|
35
|
+
Date:
|
36
|
+
- Wed, 07 May 2014 16:21:55 GMT
|
37
|
+
Connection:
|
38
|
+
- Keep-Alive
|
39
|
+
Set-Cookie:
|
40
|
+
- _ubt=; expires=Thu, 01-Jan-1970 00:00:00 GMT
|
41
|
+
body:
|
42
|
+
encoding: UTF-8
|
43
|
+
string: '{"id":"S2odxReZnGqhqxPaQ7V7kNkLoXkGZPFz","token":"eyJ0eXAiOiJKV1QiLCJhbGciOiJIUzI1NiIsImlzcyI6InVzZXItMjQxMiIsInN1YiI6IlMyb2R4UmVabkdxaHF4UGFRN1Y3a05rTG9Ya0daUEZ6IiwiYXVkIjoiODAwMDAwMDAwMDAwMDAwIiwiZXhwIjoxMzk5NDc5NzI1LCJpYXQiOjEzOTk0Nzk3MTUsImp0aSI6MX0.eyJjaGFsbGVuZ2UiOnsiaWQiOiJUVENqd3VyM3lwbTRUR1ZwWU43cENzTXFxOW9mWEVBSCIsInR5cGUiOiJvdHBfYXV0aGVudGljYXRvciJ9fQ.2UuUgl8jKkl1lhU0d2nSKmiw-Qzz130A9XJd7-swvv8","user":{"id":"8Fpmj9asxpq4mwGzx48MP1EQhdWUHDeb","local_id":"user-2412","created_at":"2014-05-07T15:33:58Z","updated_at":"2014-05-07T16:21:55Z","email":"valid@example.com","username":"valid@example.com","name":"New
|
44
|
+
Name","first_name":null,"last_name":null,"image":null,"status":"ACTIVE","mfa_enabled":true}}'
|
45
|
+
http_version:
|
46
|
+
recorded_at: Wed, 07 May 2014 16:21:55 GMT
|
47
|
+
recorded_with: VCR 2.9.0
|
@@ -0,0 +1,47 @@
|
|
1
|
+
---
|
2
|
+
http_interactions:
|
3
|
+
- request:
|
4
|
+
method: post
|
5
|
+
uri: https://:secretkey@api.castle.io/v1/sessions/eyJ0eXAiOiJKV1QiLCJhbGciOiJIUzI1NiIsImlzcyI6InVzZXItMjQxMiIsInN1YiI6IlMyb2R4UmVabkdxaHF4UGFRN1Y3a05rTG9Ya0daUEZ6IiwiYXVkIjoiODAwMDAwMDAwMDAwMDAwIiwiZXhwIjoxMzk5NDc5Njc1LCJpYXQiOjEzOTk0Nzk2NjUsImp0aSI6MH0.eyJjaGFsbGVuZ2UiOnsiaWQiOiJUVENqd3VyM3lwbTRUR1ZwWU43cENzTXFxOW9mWEVBSCIsInR5cGUiOiJvdHBfYXV0aGVudGljYXRvciJ9fQ.LT9mUzJEbsizbFxcpMo3zbms0aCDBzfgMbveMGSi1-s/verify
|
6
|
+
body:
|
7
|
+
encoding: UTF-8
|
8
|
+
string: '{"response":"017010"}'
|
9
|
+
headers:
|
10
|
+
User-Agent:
|
11
|
+
- Faraday v0.9.0
|
12
|
+
Content-Type:
|
13
|
+
- application/json
|
14
|
+
Accept-Encoding:
|
15
|
+
- gzip;q=1.0,deflate;q=0.6,identity;q=0.3
|
16
|
+
Accept:
|
17
|
+
- "*/*"
|
18
|
+
response:
|
19
|
+
status:
|
20
|
+
code: 201
|
21
|
+
message: 'Created '
|
22
|
+
headers:
|
23
|
+
Content-Type:
|
24
|
+
- application/json
|
25
|
+
Content-Length:
|
26
|
+
- '609'
|
27
|
+
X-Ua-Compatible:
|
28
|
+
- IE=Edge
|
29
|
+
Etag:
|
30
|
+
- '"27b68d405c62c2c4c2a23acafde76b26"'
|
31
|
+
Cache-Control:
|
32
|
+
- max-age=0, private, must-revalidate
|
33
|
+
Server:
|
34
|
+
- WEBrick/1.3.1 (Ruby/2.1.1/2014-02-24)
|
35
|
+
Date:
|
36
|
+
- Wed, 07 May 2014 16:22:55 GMT
|
37
|
+
Connection:
|
38
|
+
- Keep-Alive
|
39
|
+
Set-Cookie:
|
40
|
+
- _ubt=; expires=Thu, 01-Jan-1970 00:00:00 GMT
|
41
|
+
body:
|
42
|
+
encoding: UTF-8
|
43
|
+
string: '{"id":"S2odxReZnGqhqxPaQ7V7kNkLoXkGZPFz","token":"eyJ0eXAiOiJKV1QiLCJhbGciOiJIUzI1NiIsImlzcyI6InVzZXItMjQxMiIsInN1YiI6IlMyb2R4UmVabkdxaHF4UGFRN1Y3a05rTG9Ya0daUEZ6IiwiYXVkIjoiODAwMDAwMDAwMDAwMDAwIiwiZXhwIjoxMzk5NDc5NzI1LCJpYXQiOjEzOTk0Nzk3MTUsImp0aSI6MX0.e30.IRwMbLDd2LqRHB_QZvzG47eTr5vPCBrdWI6xPOPa6x4","user":{"id":"8Fpmj9asxpq4mwGzx48MP1EQhdWUHDeb","local_id":"user-2412","created_at":"2014-05-07T15:33:58Z","updated_at":"2014-05-07T16:21:55Z","email":"valid@example.com","username":"valid@example.com","name":"New
|
44
|
+
Name","first_name":null,"last_name":null,"image":null,"status":"ACTIVE","mfa_enabled":true}}'
|
45
|
+
http_version:
|
46
|
+
recorded_at: Wed, 07 May 2014 16:22:55 GMT
|
47
|
+
recorded_with: VCR 2.9.0
|
@@ -0,0 +1,44 @@
|
|
1
|
+
---
|
2
|
+
http_interactions:
|
3
|
+
- request:
|
4
|
+
method: get
|
5
|
+
uri: https://:secretkey@api.castle.io/v1/users/9RA2j3cYDxt8gefQUduKnxUxRRGy6Rz4
|
6
|
+
body:
|
7
|
+
encoding: US-ASCII
|
8
|
+
string: ''
|
9
|
+
headers:
|
10
|
+
User-Agent:
|
11
|
+
- Faraday v0.9.0
|
12
|
+
Accept-Encoding:
|
13
|
+
- gzip;q=1.0,deflate;q=0.6,identity;q=0.3
|
14
|
+
Accept:
|
15
|
+
- '*/*'
|
16
|
+
response:
|
17
|
+
status:
|
18
|
+
code: 200
|
19
|
+
message: OK
|
20
|
+
headers:
|
21
|
+
Date:
|
22
|
+
- Fri, 18 Apr 2014 23:16:44 GMT
|
23
|
+
Status:
|
24
|
+
- 200 OK
|
25
|
+
Connection:
|
26
|
+
- close
|
27
|
+
Content-Type:
|
28
|
+
- application/json
|
29
|
+
Content-Length:
|
30
|
+
- '328'
|
31
|
+
Set-Cookie:
|
32
|
+
- _ubt=; expires=Thu, 01-Jan-1970 00:00:00 GMT
|
33
|
+
X-Ua-Compatible:
|
34
|
+
- IE=Edge
|
35
|
+
Etag:
|
36
|
+
- '"73f5664d599cfbc71df7850ca66cda3d"'
|
37
|
+
Cache-Control:
|
38
|
+
- max-age=0, private, must-revalidate
|
39
|
+
body:
|
40
|
+
encoding: UTF-8
|
41
|
+
string: '{"id":"9RA2j3cYDxt8gefQUduKnxUxRRGy6Rz4","created_at":"2014-04-18T13:30:22Z","updated_at":"2014-04-18T13:33:51Z","email":"brissmyr@gmail.com","username":"brissmyr@gmail.com","name":null,"first_name":null,"last_name":null,"image":null,"status":"ACTIVE","email_verification_token":"NhFy8wBYccLsEoL-kAVt","identities":[]}'
|
42
|
+
http_version:
|
43
|
+
recorded_at: Fri, 18 Apr 2014 23:16:44 GMT
|
44
|
+
recorded_with: VCR 2.9.0
|
@@ -0,0 +1,42 @@
|
|
1
|
+
---
|
2
|
+
http_interactions:
|
3
|
+
- request:
|
4
|
+
method: get
|
5
|
+
uri: https://:secretkey@api.castle.io/v1/users/non_existing
|
6
|
+
body:
|
7
|
+
encoding: US-ASCII
|
8
|
+
string: ''
|
9
|
+
headers:
|
10
|
+
User-Agent:
|
11
|
+
- Faraday v0.9.0
|
12
|
+
Accept-Encoding:
|
13
|
+
- gzip;q=1.0,deflate;q=0.6,identity;q=0.3
|
14
|
+
Accept:
|
15
|
+
- '*/*'
|
16
|
+
response:
|
17
|
+
status:
|
18
|
+
code: 404
|
19
|
+
message: Not Found
|
20
|
+
headers:
|
21
|
+
Date:
|
22
|
+
- Fri, 18 Apr 2014 23:29:27 GMT
|
23
|
+
Status:
|
24
|
+
- 404 Not Found
|
25
|
+
Connection:
|
26
|
+
- close
|
27
|
+
Content-Type:
|
28
|
+
- application/json
|
29
|
+
Content-Length:
|
30
|
+
- '42'
|
31
|
+
Set-Cookie:
|
32
|
+
- _ubt=; expires=Thu, 01-Jan-1970 00:00:00 GMT
|
33
|
+
X-Ua-Compatible:
|
34
|
+
- IE=Edge
|
35
|
+
Cache-Control:
|
36
|
+
- no-cache
|
37
|
+
body:
|
38
|
+
encoding: UTF-8
|
39
|
+
string: '{"type":"not_found","message":"Not found"}'
|
40
|
+
http_version:
|
41
|
+
recorded_at: Fri, 18 Apr 2014 23:29:27 GMT
|
42
|
+
recorded_with: VCR 2.9.0
|
@@ -0,0 +1,46 @@
|
|
1
|
+
---
|
2
|
+
http_interactions:
|
3
|
+
- request:
|
4
|
+
method: post
|
5
|
+
uri: https://:secretkey@api.castle.io/v1/users/import
|
6
|
+
body:
|
7
|
+
encoding: UTF-8
|
8
|
+
string: '{"users":[{"email":"10@example.com","username":"10"},{"email":"20@example.com","username":"20"}]}'
|
9
|
+
headers:
|
10
|
+
User-Agent:
|
11
|
+
- Faraday v0.9.0
|
12
|
+
Content-Type:
|
13
|
+
- application/json
|
14
|
+
Accept-Encoding:
|
15
|
+
- gzip;q=1.0,deflate;q=0.6,identity;q=0.3
|
16
|
+
Accept:
|
17
|
+
- '*/*'
|
18
|
+
response:
|
19
|
+
status:
|
20
|
+
code: 201
|
21
|
+
message: Created
|
22
|
+
headers:
|
23
|
+
Date:
|
24
|
+
- Thu, 24 Apr 2014 16:19:14 GMT
|
25
|
+
Status:
|
26
|
+
- 201 Created
|
27
|
+
Connection:
|
28
|
+
- close
|
29
|
+
Content-Type:
|
30
|
+
- application/json
|
31
|
+
Content-Length:
|
32
|
+
- '85'
|
33
|
+
Set-Cookie:
|
34
|
+
- _ubt=; expires=Thu, 01-Jan-1970 00:00:00 GMT
|
35
|
+
X-Ua-Compatible:
|
36
|
+
- IE=Edge
|
37
|
+
Etag:
|
38
|
+
- '"e6928187afa7cffb7f793a998b7a1c91"'
|
39
|
+
Cache-Control:
|
40
|
+
- max-age=0, private, must-revalidate
|
41
|
+
body:
|
42
|
+
encoding: UTF-8
|
43
|
+
string: '[{"id":"fqnvfRSmxa6wqx3c6xmzDqDZrJCvtZ5P"},{"id":"4n9pcvrCSig2iVcZbk7pAMsjngzX9fgv"}]'
|
44
|
+
http_version:
|
45
|
+
recorded_at: Thu, 24 Apr 2014 16:19:14 GMT
|
46
|
+
recorded_with: VCR 2.9.0
|
@@ -0,0 +1,47 @@
|
|
1
|
+
---
|
2
|
+
http_interactions:
|
3
|
+
- request:
|
4
|
+
method: put
|
5
|
+
uri: https://:secretkey@api.castle.io/v1/users/AKfwtfrAzdDKp55aty8o14MoudkaS9BL
|
6
|
+
body:
|
7
|
+
encoding: UTF-8
|
8
|
+
string: '{"id":"AKfwtfrAzdDKp55aty8o14MoudkaS9BL","email":"updated@example.com","created_at":"2014-04-27
|
9
|
+
22:10:22 +0200"}'
|
10
|
+
headers:
|
11
|
+
User-Agent:
|
12
|
+
- Faraday v0.9.0
|
13
|
+
Content-Type:
|
14
|
+
- application/json
|
15
|
+
Accept-Encoding:
|
16
|
+
- gzip;q=1.0,deflate;q=0.6,identity;q=0.3
|
17
|
+
Accept:
|
18
|
+
- '*/*'
|
19
|
+
response:
|
20
|
+
status:
|
21
|
+
code: 200
|
22
|
+
message: OK
|
23
|
+
headers:
|
24
|
+
Date:
|
25
|
+
- Sun, 27 Apr 2014 20:10:22 GMT
|
26
|
+
Status:
|
27
|
+
- 200 OK
|
28
|
+
Connection:
|
29
|
+
- close
|
30
|
+
Content-Type:
|
31
|
+
- application/json
|
32
|
+
Content-Length:
|
33
|
+
- '252'
|
34
|
+
Set-Cookie:
|
35
|
+
- _ubt=; expires=Thu, 01-Jan-1970 00:00:00 GMT
|
36
|
+
X-Ua-Compatible:
|
37
|
+
- IE=Edge
|
38
|
+
Etag:
|
39
|
+
- '"de56261eb3d3bef170cc8e837af079fd"'
|
40
|
+
Cache-Control:
|
41
|
+
- max-age=0, private, must-revalidate
|
42
|
+
body:
|
43
|
+
encoding: UTF-8
|
44
|
+
string: '{"id":"AKfwtfrAzdDKp55aty8o14MoudkaS9BL","created_at":"2014-04-27T20:10:22Z","updated_at":"2014-04-27T20:10:22Z","email":"updated@example.com","username":"updated@example.com","name":null,"first_name":null,"last_name":null,"image":null,"status":"ACTIVE","identities":[]}'
|
45
|
+
http_version:
|
46
|
+
recorded_at: Sun, 27 Apr 2014 20:10:22 GMT
|
47
|
+
recorded_with: VCR 2.9.0
|
@@ -0,0 +1,38 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe 'Castle helpers' do
|
4
|
+
let(:token) { 'eyJ0eXAiOiJKV1QiLCJhbGciOiJIUzI1NiIsImlhdCI6MTM5ODIzOTIwMywiZXhwIjoxMzk4MjQyODAzfQ.eyJ1c2VyX2lkIjoiZUF3djVIdGRiU2s4Yk1OWVpvanNZdW13UXlLcFhxS3IifQ.Apa7EmT5T1sOYz4Af0ERTDzcnUvSalailNJbejZ2ddQ' }
|
5
|
+
|
6
|
+
xit 'creates a session' do
|
7
|
+
Castle::Session.should_receive(:post).
|
8
|
+
with("users/user%201234/sessions", user: {email: 'valid@example.com'}).
|
9
|
+
and_return(Castle::Session.new(token: token))
|
10
|
+
Castleauthenticate(nil, 'user 1234', properties: {email: 'valid@example.com'})
|
11
|
+
end
|
12
|
+
|
13
|
+
xit 'refreshes, and does not create a session' do
|
14
|
+
Castle::Session.should_not_receive(:create)
|
15
|
+
Castle::Session.any_instance.should_receive(:refresh).
|
16
|
+
and_return(Castle::Session.new(token: token))
|
17
|
+
opts = {
|
18
|
+
user_id: '1234',
|
19
|
+
properties: {
|
20
|
+
email: 'valid@example.com'
|
21
|
+
},
|
22
|
+
context: {
|
23
|
+
ip: '8.8.8.8',
|
24
|
+
user_agent: 'Mozilla'
|
25
|
+
}
|
26
|
+
}
|
27
|
+
Castleauthenticate(token, opts)
|
28
|
+
end
|
29
|
+
|
30
|
+
xit 'deauthenticates with context' do
|
31
|
+
Castle::Session.should_receive(:destroy_existing)
|
32
|
+
|
33
|
+
jwt = Castle::JWT.new(token)
|
34
|
+
jwt.merge!(context: { ip: '8.8.8.8', user_agent: 'Mozilla' })
|
35
|
+
|
36
|
+
Castledeauthenticate(jwt.to_token)
|
37
|
+
end
|
38
|
+
end
|