Skip to content

Commit 2626a33

Browse files
authored
[v1.4] Adds Device Code Flow (#5)
The Device Code grant type is used by browserless or input-constrained devices in the device flow to exchange a previously obtained device code for an access token. The Device Code grant type value is urn:ietf:params:oauth:grant-type:device_code.
1 parent c59d667 commit 2626a33

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

49 files changed

+511
-253
lines changed

.github/workflows/spec.yml

+6-3
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ on:
44
pull_request:
55
branches: [main]
66
jobs:
7-
docker:
7+
build:
88
timeout-minutes: 10
99
runs-on: ubuntu-latest
1010
services:
@@ -42,7 +42,7 @@ jobs:
4242
- name: Run Code Format
4343
run: crystal tool format --check
4444

45-
- name: Install dependencies
45+
- name: Install Dependencies
4646
run: shards install
4747

4848
- name: Run Ameba Checks
@@ -54,8 +54,11 @@ jobs:
5454
- name: Run tests
5555
run: crystal spec
5656
env:
57+
BASE_URL: http://localhost:4000
58+
ACTIVATE_URL: http://localhost:4000/activate
59+
DEVICE_CODE_TTL: 300
5760
SECRET_KEY: secret_key
5861
REFRESH_TTL: 60
59-
CODE_TTL: 5
62+
CODE_TTL: 300
6063
ACCESS_TOKEN_TTL: 60
6164
DATABASE_URL: postgres://auth_user:auth_pass@localhost:5432/authority_db?initial_pool_size=10&checkout_timeout=3

Authority.session.sql

Whitespace-only changes.

Dockerfile.spec

-26
This file was deleted.

README.md

+44-15
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,16 @@
11
# Authority
22

3-
[![Test](https://github.com/azutoolkit/authority/actions/workflows/spec.yml/badge.svg)](https://github.com/azutoolkit/authority/actions/workflows/spec.yml) [![Codacy Badge](https://app.codacy.com/project/badge/Grade/c19b4551de9f43c2b79664af5908f033)](https://www.codacy.com/gh/azutoolkit/authority/dashboard?utm_source=github.com&utm_medium=referral&utm_content=azutoolkit/authority&utm_campaign=Badge_Grade)
3+
[![Test](https://github.com/azutoolkit/authority/actions/workflows/spec.yml/badge.svg)](https://github.com/azutoolkit/authority/actions/workflows/spec.yml) [![Codacy Badge](https://app.codacy.com/project/badge/Grade/c19b4551de9f43c2b79664af5908f033)](https://www.codacy.com/gh/azutoolkit/authority/dashboard?utm_source=github.com&utm_medium=referral&utm_content=azutoolkit/authority&utm_campaign=Badge_Grade) ![GitHub release (latest by date)](https://img.shields.io/github/v/release/azutoolkit/authority?label=shard)
44

55
![logo](https://user-images.githubusercontent.com/1685772/141647649-241cff93-a5dc-4e6a-9695-ff4b9e6a51d4.png)
66

77
<https://user-images.githubusercontent.com/1685772/140772737-179dd2e4-0eaa-4915-a942-5e0fe48f0124.mp4>
88

99
A OAuth2 Server, sometimes also referred to as an OAuth 2.0 Server, OAuth Server, Authorization Server, is a software system that implements network protocol flows that allow a client software application to act on behalf of a user.
1010

11-
Authority is a OpenID OAuth 2.0 Server and OpenID Connect Provider optimized for low-latency, high throughput, and low resource consumption. Authority has a built in identity provider user login.
11+
Authority is a OpenID OAuth 2.0 Server and OpenID Connect Provider written in Crystal optimized for low-latency, high throughput, and low resource consumption. Authority has a built in identity provider user login.
1212

13-
OpenID Connect and OAuth Provider written in Crystal - Security-first, open source API security for your infrastructure. SDKs to come.
13+
Authority is an open source API security for your infrastructure.
1414

1515
## Architecture
1616

@@ -34,11 +34,19 @@ of Authority is to make OAuth 2.0 and OpenID Connect 1.0 better accessible.
3434

3535
The Authority implements five grants for acquiring an access token:
3636

37-
- Authorization code grant
38-
- Implicit grant
39-
- Resource owner credentials grant
40-
- Client credentials grant
41-
- Refresh token grant
37+
- Authorization code Grant
38+
- Implicit Grant
39+
- Resource owner credentials Grant
40+
- Client credentials Grant
41+
- Refresh token Grant
42+
- Device Token Grant
43+
44+
The following RFCs are implemented:
45+
46+
- [RFC6749 "OAuth 2.0"](https://tools.ietf.org/html/rfc6749)
47+
- [RFC6750 " The OAuth 2.0 Authorization Framework: Bearer Token Usage"](https://tools.ietf.org/html/rfc6750)
48+
- [RFC7519 "JSON Web Token (JWT)"](https://tools.ietf.org/html/rfc7519)
49+
- [RFC7636 "Proof Key for Code Exchange by OAuth Public Clients"](https://tools.ietf.org/html/rfc7636)
4250

4351
## Why Authority is Different​
4452

@@ -70,12 +78,11 @@ Grant Types
7078
- [x] OpenID Connect
7179
- [x] PKCE
7280
- [x] JSON Web Tokens
73-
- [ ] Device Code grant
81+
- [x] Device Code grant
7482
- [ ] Token Introspection
7583
- [ ] Token Revocation
76-
- [ ] Opaque Token
84+
- [ ] Opaque Tokens
7785
- [ ] Client SDKs
78-
- [ ] Session Management
7986
- [ ] Account recovery & verification
8087
- [ ] MFA
8188
- [ ] Permission and Role Management
@@ -95,24 +102,36 @@ CRYSTAL_WORKERS=4
95102
PORT=4000
96103
PORT_REUSE=true
97104
HOST=0.0.0.0
98-
DATABASE_URL=postgres://auth_user:auth_pass@db:5432/authority_db
99-
?initial_pool_size=10&checkout_timeout=3
105+
DATABASE_URL=postgres://auth_user:auth_pass@db:5432/authority_db?initial_pool_size=10&checkout_timeout=3
100106
SECRET_KEY=secret_key
101107
REFRESH_TTL=60
102108
CODE_TTL=5
103109
ACCESS_TOKEN_TTL=60
110+
TEMPLATES_PATH="./public/templates"
111+
ERROR_TEMPLATE
112+
SESSION_KEY="session_id"
113+
BASE_URL=http://localhost:4000
114+
ACTIVATE_URL=http://localhost:4000/activate
115+
DEVICE_CODE_TTL=300
116+
SSL_CERT=
117+
SSL_KEY=
118+
SSL_CA=
119+
SSL_MODE=
104120
```
105121

106122
## User Interface Customization
107123

108-
The Managed UI implements screens such as login, registration, account recovery,
124+
The Authority UI implements screens such as login, registration, account recovery,
109125
account setting, and account verification. This allows for fast adoption of Authority.
110126

111127
Contrary to other vendors, Authority allows you to implement your own UI
112128
by offering simple html templates. You can change the look of Authority `signin`
113129
and `authorize` html pages.
114130

115-
Just edit the `./public/templates/signin.html` and `./public/templates/authorize.html`
131+
Just edit the `./public/templates/`
132+
133+
> **Note** ensure to maintain the same template variable names defined in
134+
> brackets `{{var_name}}`
116135
117136
## Installation
118137

@@ -124,6 +143,16 @@ Spin up your server
124143
docker-compose up server
125144
```
126145

146+
## Which OAuth 2.0 grant should I use?
147+
148+
A grant is a method of acquiring an access token. Deciding which grants to
149+
implement depends on the type of client the end user will be using, and the
150+
experience you want for your users.
151+
152+
<p align="center">
153+
<img src="https://user-images.githubusercontent.com/1685772/142732731-bfaa94ab-5072-4a70-b91c-72c8b1b10f28.png">
154+
</p>
155+
127156
## Contributing
128157

129158
1. Fork it (<https://github.com/azutoolkit/authority/fork>)
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
class CreateDeviceCode
2+
include Clear::Migration
3+
4+
def change(direction)
5+
direction.up do
6+
create_enum("verification", %w(allowed denied pending))
7+
8+
create_table :device_codes, id: :uuid do |t|
9+
t.column :client_id, "varchar(80)", null: false, index: true, unique: false
10+
t.column :client_name, "varchar(80)", null: false
11+
t.column :user_code, "varchar(10)", null: false, index: true, unique: false
12+
t.column :verification, :verification, null: false
13+
t.column :verification_uri, "varchar(1000)", null: false
14+
t.column :expires_at, "TIMESTAMPTZ", index: true, default: "CURRENT_TIMESTAMP"
15+
16+
t.timestamps
17+
end
18+
end
19+
20+
direction.down do
21+
execute "DROP TABLE IF EXISTS device_codes;"
22+
execute "DROP TYPE IF EXISTS verification;"
23+
end
24+
end
25+
end

docker-compose.yml

-11
Original file line numberDiff line numberDiff line change
@@ -10,17 +10,6 @@ services:
1010
ports:
1111
- 5432:5432
1212

13-
# spec:
14-
# build:
15-
# context: .
16-
# dockerfile: Dockerfile.spec
17-
# container_name: authority-spec
18-
# working_dir: /opt/app
19-
# environment:
20-
# - DATABASE_URL=postgres://auth_user:auth_pass@db:5432/authority_db
21-
# depends_on:
22-
# - server
23-
2413
server:
2514
build:
2615
context: .

local.env

+7-1
Original file line numberDiff line numberDiff line change
@@ -9,4 +9,10 @@ DATABASE_URL=postgres://auth_user:auth_pass@db:5432/authority_db?initial_pool_si
99
SECRET_KEY=secret_key
1010
REFRESH_TTL=60
1111
CODE_TTL=5
12-
ACCESS_TOKEN_TTL=60
12+
ACCESS_TOKEN_TTL=60
13+
TEMPLATES_PATH="./public/templates"
14+
ERROR_TEMPLATE
15+
SESSION_KEY="session_id"
16+
BASE_URL=http://localhost:4000
17+
ACTIVATE_URL=http://localhost:4000/activate
18+
DEVICE_CODE_TTL=300

oauth-grants.png

58 KB
Loading

public/css/main.css

-114
Original file line numberDiff line numberDiff line change
@@ -20,112 +20,12 @@ body {
2020
font-size: 62px;
2121
}
2222

23-
.form-control {
24-
height: 41px;
25-
background: #f2f2f2;
26-
box-shadow: none !important;
27-
border: none;
28-
}
29-
30-
.form-control:focus {
31-
border-color: #2389cd;
32-
}
33-
34-
.login-form {
35-
width: 400px;
36-
margin: 30px auto;
37-
padding: 30px 0;
38-
}
39-
40-
.login-form form {
41-
color: #999;
42-
border-radius: 3px;
43-
margin-bottom: 15px;
44-
background: #fff;
45-
box-shadow: 0px 2px 2px rgba(0, 0, 0, 0.3);
46-
padding: 30px;
47-
}
48-
49-
.login-form h4 {
50-
text-align: center;
51-
font-size: 22px;
52-
margin-bottom: 20px;
53-
}
54-
55-
.login-form .form-group {
56-
margin-bottom: 20px;
57-
}
58-
59-
.login-form .form-control,
60-
.login-form .btn {
61-
min-height: 40px;
62-
border-radius: 2px;
63-
transition: all 0.5s;
64-
}
65-
66-
.login-form .close {
67-
position: absolute;
68-
top: 15px;
69-
right: 15px;
70-
}
71-
72-
.login-form .btn,
73-
.login-form .btn:active {
74-
background: #2389cd !important;
75-
border: none;
76-
line-height: normal;
77-
}
78-
79-
.login-form .btn:hover,
80-
.login-form .btn:focus {
81-
background: #2389cd !important;
82-
}
83-
84-
.login-form .checkbox-inline {
85-
float: left;
86-
}
87-
88-
.login-form input[type="checkbox"] {
89-
position: relative;
90-
top: 2px;
91-
}
92-
93-
.login-form .forgot-link {
94-
float: right;
95-
}
96-
97-
.login-form .small {
98-
font-size: 13px;
99-
}
100-
101-
.login-form a {
102-
color: #2389cd;
103-
}
104-
105-
.form-control {
106-
height: 41px;
107-
background: #f2f2f2;
108-
box-shadow: none !important;
109-
border: none;
110-
}
111-
112-
.form-control:focus {
113-
background: #e2e2e2;
114-
}
115-
116-
.form-control,
117-
.btn {
118-
border-radius: 3px;
119-
}
120-
12123
.signup-form {
12224
width: 500px;
12325
margin: 30px auto;
12426
padding: 30px 0;
12527
}
12628

127-
128-
12929
.signup-form form {
13030
color: #999;
13131
border-radius: 3px;
@@ -161,20 +61,6 @@ body {
16161
padding-left: 10px;
16262
}
16363

164-
.signup-form .btn {
165-
font-size: 16px;
166-
font-weight: bold;
167-
background: #3598dc;
168-
border: none;
169-
min-width: 140px;
170-
}
171-
172-
.signup-form .btn:hover,
173-
.signup-form .btn:focus {
174-
background: #2389cd !important;
175-
outline: none;
176-
}
177-
17864
.signup-form a:hover {
17965
text-decoration: none;
18066
}

public/templates/authorize_form.html

+1-1
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
{% set title = "Authorize" %}
33

44
{% block body %}
5-
<main class="login-form">
5+
<main class="signup-form">
66
{% include "errors.html" %}
77
<form method="post" action="{{authorize_endpoint}}">
88
<input type="hidden" name="response_type" value="{{response_type}}" />
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
{% extends "layout.html" %}
2+
{% set title = "Device Activation" %}
3+
4+
{% block body %}
5+
<main class="signup-form">
6+
7+
{% include "errors.html" %}
8+
<form>
9+
<h2 class="text-center display-3 text-success fw-light">Congratulations, you're all set!</h2>
10+
</form>
11+
</main>
12+
{% endblock %}

0 commit comments

Comments
 (0)