Skip to content

Commit da2b449

Browse files
committed
Merge branch 'device-code'
2 parents d0b8fe8 + c4f6df0 commit da2b449

21 files changed

+180
-171
lines changed

README.md

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -32,11 +32,9 @@ The following RFCs are implemented:
3232
- [RFC7519 "JSON Web Token (JWT)"](https://tools.ietf.org/html/rfc7519)
3333
- [RFC7636 "Proof Key for Code Exchange by OAuth Public Clients"](https://tools.ietf.org/html/rfc7636)
3434

35-
3635
Please refer to the project documentation to get started
3736

38-
[![documentation](https://img.shields.io/badge/documentation-authority-brightgreen?style=for-the-badge)](https://azutopia.gitbook.io/authority)
39-
37+
[![documentation](https://img.shields.io/badge/documentation-authority-brightgreen?style=for-the-badge)](https://azutopia.gitbook.io/authority)
4038

4139
## Contributing
4240

db/migrations/1637251606_create_device_code.cr

Lines changed: 0 additions & 25 deletions
This file was deleted.

shard.lock

Lines changed: 15 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -7,47 +7,47 @@ shards:
77

88
ameba:
99
git: https://github.com/crystal-ameba/ameba.git
10-
version: 1.3.1
10+
version: 1.6.1
1111

1212
authly:
1313
git: https://github.com/azutoolkit/authly.git
14-
version: 1.1.1
14+
version: 1.2
1515

1616
azu:
1717
git: https://github.com/azutoolkit/azu.git
18-
version: 0.4.6
18+
version: 0.4.11
1919

2020
backtracer:
2121
git: https://github.com/sija/backtracer.cr.git
2222
version: 1.2.2
2323

2424
bindata:
2525
git: https://github.com/spider-gazelle/bindata.git
26-
version: 1.11.1
26+
version: 2.0.0
2727

2828
clear:
2929
git: https://github.com/anykeyh/clear.git
3030
version: 0.9+git.commit.480289555c833793fa6964398fefec6b7e25168d
3131

3232
crinja:
3333
git: https://github.com/straight-shoota/crinja.git
34-
version: 0.8.0
34+
version: 0.8.1
3535

3636
datadog:
3737
git: https://github.com/jgaskins/datadog.git
38-
version: 0.1.0+git.commit.d68ff5dd17ee93476700aba1eb1c25d6c577ddd2
38+
version: 0.1.0+git.commit.9808f7ceb663f4b87f321eb909469f46e5bf1663
3939

4040
db:
4141
git: https://github.com/crystal-lang/crystal-db.git
4242
version: 0.10.1
4343

4444
exception_page:
4545
git: https://github.com/crystal-loot/exception_page.git
46-
version: 0.3.0
46+
version: 0.4.1
4747

4848
faker:
4949
git: https://github.com/askn/faker.git
50-
version: 0.8.0
50+
version: 0.9.0
5151

5252
flux:
5353
git: https://github.com/azutoolkit/flux.git
@@ -63,19 +63,19 @@ shards:
6363

6464
jwt:
6565
git: https://github.com/crystal-community/jwt.git
66-
version: 1.6.0
66+
version: 1.6.1
6767

6868
marionette: # Overridden
6969
git: https://github.com/eliasjpr/marionette.git
7070
version: 0.3.0+git.commit.e62088de613a7f5002b5381478bc9e15c754d419
7171

7272
msgpack:
7373
git: https://github.com/crystal-community/msgpack-crystal.git
74-
version: 1.3.3
74+
version: 1.3.4
7575

7676
openssl_ext:
7777
git: https://github.com/spider-gazelle/openssl_ext.git
78-
version: 2.2.0
78+
version: 2.4.4
7979

8080
pg: # Overridden
8181
git: https://github.com/will/crystal-pg.git
@@ -91,17 +91,17 @@ shards:
9191

9292
redis:
9393
git: https://github.com/stefanwille/crystal-redis.git
94-
version: 2.8.3
94+
version: 2.9.1
9595

9696
schema:
9797
git: https://github.com/azutoolkit/schema.git
98-
version: 0.2.2
98+
version: 0.2.7
9999

100100
session:
101101
git: https://github.com/azutoolkit/session.git
102-
version: 1.0.4
102+
version: 1.0.8
103103

104104
statsd:
105105
git: https://github.com/miketheman/statsd.cr.git
106-
version: 0.5.0+git.commit.6065b3635304d0e80ea05cb5030a576b0b55195b
106+
version: 0.5.0+git.commit.f0820fac6d1f8d45ab36361573ad23d740146c47
107107

shard.yml

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
name: authority
22
version: 1.4.5
3-
crystal: 1.6.2
43
license: MIT
54
authors:
65
- Elias Perez <eliasjpr@gmail.com>
@@ -17,7 +16,7 @@ dependencies:
1716
branch: master
1817
authly:
1918
github: azutoolkit/authly
20-
version: 1.1.1
19+
version: 1.2.0
2120
datadog:
2221
github: jgaskins/datadog
2322
development_dependencies:

spec/flows/authorization_code_flux.cr

Lines changed: 25 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -7,27 +7,47 @@ class AuthorizationCodeFlux < Flux
77
end
88

99
def initialize(@url : String, @username : String, @password : String)
10-
options = Marionette.firefox_options(args: ["-headless"])
10+
options = Marionette.firefox_options(args: [""])
1111
super(Marionette::Browser::Firefox, options)
1212
end
1313

1414
def call
15-
redirect = step do
15+
redirect, all_cookies = step do
1616
visit @url
1717

1818
sleep 1.seconds
1919

2020
fill "#username", @username, by: :css
2121
fill "#password", @password, by: :css
2222
submit "#signin", by: :css
23+
session_cookies = execute("GetAllCookies")
2324

2425
sleep 1.seconds
25-
2626
submit "#approve", by: :css
27+
sleep 2.seconds
28+
{URI.parse(current_url).query_params, session_cookies}
29+
end
30+
31+
{redirect["code"].to_s, redirect["state"].to_s, parse_cookies(all_cookies)}
32+
end
2733

28-
URI.parse(current_url).query_params
34+
def parse_cookies(all_cookies)
35+
cookies = HTTP::Cookies.new
36+
headers = HTTP::Headers.new
37+
38+
all_cookies.as_a.each do |c|
39+
cookies << HTTP::Cookie.new(
40+
name: c["name"].as_s,
41+
value: c["value"].as_s,
42+
path: c["path"].as_s,
43+
expires: c["expiry"].as_i64.minutes.from_now,
44+
domain: c["domain"].as_s,
45+
secure: c["secure"].as_bool,
46+
http_only: c["secure"].as_bool,
47+
samesite: HTTP::Cookie::SameSite.parse(c["sameSite"].as_s)
48+
)
2949
end
3050

31-
{redirect["code"].to_s, redirect["state"].to_s}
51+
cookies.add_request_headers(headers)
3252
end
3353
end

spec/spec_helper.cr

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -28,16 +28,16 @@ Clear::SQL.truncate("owners", cascade: true)
2828
Clear::SQL.truncate("clients", cascade: true)
2929
create_client(CLIENT_ID, CLIENT_SECRET, REDIRECT_URI)
3030

31-
process = Process.new(
32-
"./bin/authority",
33-
env: ENV.to_h,
34-
output: Process::Redirect::Inherit,
35-
error: Process::Redirect::Inherit)
36-
# Wait for process to start
37-
sleep 1.seconds
31+
# process = Process.new(
32+
# "./bin/authority",
33+
# env: ENV.to_h,
34+
# output: Process::Redirect::Inherit,
35+
# error: Process::Redirect::Inherit)
36+
# # Wait for process to start
37+
# sleep 1.seconds
3838

3939
Spec.after_suite do
40-
process.not_nil!.signal Signal::KILL
40+
# process.not_nil!.signal Signal::KILL
4141
end
4242

4343
Spec.before_each do

src/authority.cr

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,12 +3,12 @@ require "digest"
33
require "schema"
44
require "./config/**"
55
require "./helpers/**"
6-
require "./entities/**"
7-
require "./repositories/**"
86
require "./validators/**"
9-
require "./services/**"
7+
require "./entities/**"
108
require "./requests/**"
9+
require "./repositories/**"
1110
require "./providers/**"
11+
require "./services/**"
1212
require "./responses/**"
1313
require "./endpoints/**"
1414
require "../db/migrations/**"

src/config/authority.cr

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,18 @@
11
require "azu"
22
Log.setup_from_env
33

4-
# Docs - https://azutopia.gitbook.io/azu/defining-your-app
54
module Authority
6-
# Defines Azu Framework
75
include Azu
86

97
SESSION_KEY = ENV.fetch "SESSION_KEY", "session_id"
108
BASE_URL = ENV.fetch "BASE_URL", "http://localhost:4000"
119
ACTIVATE_URL = "#{BASE_URL}/activate"
1210
DEVICE_CODE_TTL = ENV.fetch("DEVICE_CODE_TTL", "300").to_i
1311
SESSION = Session::CookieStore(UserSession).provider
14-
HANDLERS = [
15-
Azu::Handler::RequestID.new,
12+
13+
HANDLERS = [
1614
Azu::Handler::Rescuer.new,
15+
Azu::Handler::RequestID.new,
1716
Azu::Handler::Logger.new,
1817
Session::SessionHandler.new(Authority.session),
1918
]
@@ -22,9 +21,12 @@ module Authority
2221
SESSION
2322
end
2423

24+
def self.current_session
25+
SESSION.current_session
26+
end
27+
2528
configure do |c|
2629
c.templates.path = ENV["TEMPLATE_PATH"]
27-
# Static Assets Handler
2830
c.router.get "/*", Handler::Static.new
2931
end
3032
end

src/config/datadog.cr

Lines changed: 0 additions & 41 deletions
This file was deleted.

src/endpoints/authorize/new_endpoint.cr

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ module Authority::Authorize
77
get "/authorize"
88

99
def call : Response | FormResponse
10-
return signin unless current_session.authenticated?
10+
return redirect_to_signin unless authenticated?
1111

1212
header "Content-Type", "text/html; charset=UTF-8"
1313
header "Cache-Control", "no-store"

0 commit comments

Comments
 (0)