Skip to content

Commit bbe52d2

Browse files
committed
merge: 'implement-basic-functionality' into 'main'
Implement basic functionality See merge request namib-master/libraries/dart_dcaf!2
2 parents 77275c5 + e1f76fd commit bbe52d2

32 files changed

+3504
-17
lines changed

.gitignore

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
# Files and directories created by pub.
2+
.dart_tool/
3+
.packages
4+
5+
# Conventional directory for build outputs.
6+
build/
7+
8+
# Omit committing pubspec.lock for library packages; see
9+
# https://dart.dev/guides/libraries/private-files#pubspeclock.
10+
pubspec.lock
11+
12+
.idea

.gitlab-ci.yml

Lines changed: 67 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,67 @@
1+
# https://hub.docker.com/_/dart
2+
image: dart:beta
3+
4+
variables:
5+
PUB_VARS: "--platform vm --timeout 30s --concurrency=6 --test-randomize-ordering-seed=random --reporter=json"
6+
7+
# Cache downloaded dependencies and plugins between builds.
8+
# To keep cache across branches add 'key: "$CI_JOB_NAME"'
9+
cache:
10+
paths:
11+
- .pub-cache/global_packages
12+
13+
before_script:
14+
- export PATH="$PATH":"~/.pub-cache/bin"
15+
- pub get --no-precompile
16+
- pub global activate junitreport
17+
- pub global activate coverage
18+
- pub global activate -sgit https://github.com/Workiva/lsif_indexer
19+
- apt -qq update
20+
- apt -qq install -y lcov python3 python3-distutils # unfortunately necessary to convert lcov reports to cobertura
21+
- curl -o lcov_cobertura.py https://raw.githubusercontent.com/eriwen/lcov-to-cobertura-xml/master/lcov_cobertura/lcov_cobertura.py
22+
23+
style_check:
24+
stage: test
25+
script:
26+
- dart format -o none --set-exit-if-changed .
27+
28+
lint:
29+
stage: test
30+
script:
31+
- dart analyze .
32+
33+
test:
34+
stage: test
35+
script:
36+
- pub run test $PUB_VARS --coverage=./coverage > report.jsonl
37+
- pub global run junitreport:tojunit --input report.jsonl --output report.xml
38+
- pub global run coverage:format_coverage --packages=.packages --report-on=lib --lcov -o ./coverage/lcov.info -i ./coverage
39+
- python3 lcov_cobertura.py ./coverage/lcov.info -o ./coverage.xml
40+
- genhtml coverage/lcov.info
41+
coverage: '/lines\.*: \d+\.\d+\%/'
42+
artifacts:
43+
when: always
44+
reports:
45+
junit:
46+
- report.xml
47+
cobertura:
48+
- coverage.xml
49+
50+
code_quality:
51+
stage: test
52+
script:
53+
- dart run dart_code_metrics:metrics analyze lib -r gitlab > quality.json
54+
artifacts:
55+
when: always
56+
reports:
57+
codequality:
58+
- quality.json
59+
60+
code_navigation:
61+
stage: test
62+
allow_failure: true
63+
script:
64+
- pub global run lsif_indexer -o dump.lsif
65+
artifacts:
66+
reports:
67+
lsif: dump.lsif

CHANGELOG.md

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
# Changelog
2+
All notable changes to this project will be documented in this file.
3+
4+
The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
5+
and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).
6+
7+
## 0.1.0-pre --- 2022-04-27
8+
- CBOR de-/serializable model of the ACE-OAuth framework has been added:
9+
- Binary-, text-encoded and [AIF](https://datatracker.ietf.org/doc/html/draft-ietf-ace-aif)-scopes
10+
- A variant of the AIF format specific to [libdcaf](https://gitlab.informatik.uni-bremen.de/DCAF/dcaf) is also supported
11+
- Access token requests and responses
12+
- Authorization server request creation hints
13+
- Error responses
14+
- Various smaller types (`CoseKey`, `GrantType`, `ProofOfPossessionKey`, `TokenType`...)
15+
- Use `serialize()` or `fromSerialized()` to serialize and deserialize these types.
16+
- Pre-release because we depend on the Dart Beta SDK (2.17.0).

CODEOWNERS

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,4 +3,4 @@
33
# https://docs.gitlab.com/ee/user/project/code_owners.html
44

55
[Maintainers]
6-
# * [ENTER USERNAME HERE AND UNCOMMENT]
6+
* @falko1

LICENSE

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
LICENSE-MIT

LICENSE-MIT

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
MIT License
22

3-
Copyright (c) 2021 The NAMIB Project Developers
3+
Copyright (c) 2022 The NAMIB Project Developers
44

55
Permission is hereby granted, free of charge, to any person obtaining a copy
66
of this software and associated documentation files (the "Software"), to deal

README.md

Lines changed: 96 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,98 @@
1-
# [PROJECT NAME HERE]
1+
# dart_dcaf
22

3-
[PROJECT SHORT DESCRIPTION HERE]
3+
[![pub.dev](https://img.shields.io/pub/v/dcaf?style=for-the-badge)](https://pub.dev/packages/dcaf)
44

5-
## **IMPORTANT NOTES CONCERNING THE TEMPLATE**
5+
An implementation of the [ACE-OAuth] framework in Dart.
66

7-
After creating the repository, perform the steps detailed in [the current version of the Git workflow document](https://hackmd.informatik.uni-bremen.de/s/w8tkKT_SZ).
7+
This library implements the ACE-OAuth
8+
(Authentication and Authorization for Constrained Environments
9+
using the OAuth 2.0 Framework) framework as defined in
10+
[`draft-ietf-ace-oauth-authz-46`](https://www.ietf.org/archive/id/draft-ietf-ace-oauth-authz-46.html).
11+
Its main feature is CBOR-(de-)serializable data models such as `AccessTokenRequest`.
812

9-
The most important steps that need to be performed are:
10-
1. Set at least one maintainer **in the CODEOWNERS file**, **at the end of this README document** and **in the GitLab project member settings (under "Project information")**.
11-
2. Check that the **push rules**, the **merge approval and merge request settings** as well as the **protected branch settings** match the ones detailed in the Git workflow document.
12-
3. Check that the License suggested in this template (Apache 2.0/MIT dual license) is actually the one you want for this project.
13-
4. Enable/disable GitLab project features as needed (Settings->General)
14-
4. Update this README file, adding a short repository description and other relevant information (like build instructions) and removing this part of the document.
15-
5. **Rewrite/Replace** the initial commit so that the first commit includes all the changes you have made (as well as other things the repository should inlcude in the first commit) and **force push** the initial commit (you might have to disable the branch protection temporarily for this).
13+
## Features
14+
- CBOR de-/serializable model of the ACE-OAuth framework:
15+
- Binary-, text-encoded and [AIF](https://datatracker.ietf.org/doc/html/draft-ietf-ace-aif)-scopes
16+
- A variant of the AIF format specific to [libdcaf](https://gitlab.informatik.uni-bremen.de/DCAF/dcaf) is also supported
17+
- *Note that dynamic REST methods in AIF currently don't (de)serialize correctly on the Web platform!*
18+
- Access token requests and responses
19+
- Authorization server request creation hints
20+
- Error responses
21+
- Various smaller types (`CoseKey`, `GrantType`, `ProofOfPossessionKey`, `TokenType`...)
22+
- Use `serialize()` or `fromSerialized()` to serialize and deserialize these types.
1623

17-
If there are any questions or suggestions you can contact the Git workflow group (@s_edhnm5, @falko1, @hdamer) via Mattermost.
24+
> Note that actually transmitting the serialized values (e.g. via CoAP)
25+
is *out of scope* for this library.
26+
27+
## Getting started
28+
29+
**Note that this package is currently in pre-release, mainly because we depend
30+
on Dart 2.17.0, which is still in Beta at the time of writing.**
31+
32+
All you need to do to get started is to add this package to your `pubspec.yaml`.
33+
You can then import it using `import 'package:dcaf/dcaf.dart`.
34+
35+
## Usage
36+
37+
As mentioned, the main feature of this library is ACE-OAuth data models.
38+
39+
[For example](https://www.ietf.org/archive/id/draft-ietf-ace-oauth-authz-46.html#figure-7),
40+
say you (the client) want to request an access token from an
41+
Authorization Server. For this, you'd need to create an `AccessTokenRequest`,
42+
which has to include at least a `clientId`. We'll also specify an audience,
43+
a scope (using `TextScope`---note that `BinaryScope`s or `AifScope`s would also work),
44+
as well as a `ProofOfPossessionKey`
45+
(the key the access token should be bound to) in the `reqCnf` field.
46+
47+
Creating, serializing and then de-serializing such
48+
a structure would look like this:
49+
```dart
50+
final request = AccessTokenRequest(
51+
clientId: "myclient",
52+
audience: "valve242",
53+
scope: TextScope("read"),
54+
reqCnf: KeyId([0xDC, 0xAF]));
55+
final List<int> serialized = request.serialize();
56+
assert(AccessTokenRequest.fromSerialized(serialized) == request);
57+
```
58+
59+
Its CBOR representation (using CBOR diagnostic notation) would look like this:
60+
```text
61+
{
62+
"client_id" : "myclient",
63+
"audience" : "valve424",
64+
"scope" : "read",
65+
"req_cnf" : {
66+
"kid" : h'dcaf'
67+
}
68+
}
69+
```
70+
(Note that abbreviations aren't used here,
71+
so keep in mind that the labels are really integers instead of strings.)
72+
73+
## Additional information
74+
75+
This library is heavily based on [`dcaf-rs`](https://crates.io/crates/dcaf),
76+
a similar implementation of the ACE-OAuth framework in Rust, which is
77+
intended for all actors in the ACE-OAuth protocol flow
78+
(e.g. Authorization Servers too). In contrast, this library is mainly
79+
intended for the "Client", hence missing some features present in `dcaf-rs`.
80+
Whenever I update `dcaf-rs`, I will try to add the new functionality to
81+
this library as well (if applicable).
82+
83+
The name DCAF was chosen because eventually, it's planned for this
84+
library to support functionality from the [Delegated CoAP Authentication and
85+
Authorization Framework (DCAF)](https://dcaf.science/)
86+
specified in [`draft-gerdes-ace-dcaf-authorize`](https://datatracker.ietf.org/doc/html/draft-gerdes-ace-dcaf-authorize-04)
87+
(which was specified prior to ACE-OAuth and inspired many design
88+
choices in it)---specifically, it's planned to support using a CAM
89+
(Client Authorization Manager)
90+
instead of just a SAM (Server Authorization Manager),
91+
as is done in ACE-OAuth.
92+
Compatibility with the existing [DCAF implementation in C](https://gitlab.informatik.uni-bremen.de/DCAF/dcaf)
93+
(which we'll call `libdcaf` to disambiguate from `dcaf` referring
94+
to this library) is also an additional design goal, though the primary
95+
objective is still to support ACE-OAuth.
1896

1997
## License
2098

@@ -37,6 +115,9 @@ dual licensed as above, without any additional terms or conditions.
37115

38116
This project is currently maintained by the following developers:
39117

40-
| Name | Email Address | GitHub Username |
41-
|:----------:|:--------------------:|:--------------------------------------------:|
42-
| [MAINTAINER NAME] | [MAINTAINER UNIVERSITY EMAIL] | [[GITHUB_USERNAME]]([GITHUB_PROFILE_URL]) |
118+
| Name | Email Address | GitHub Username |
119+
|:--------------:|:--------------------:|:-------------------------------------:|
120+
| Falko Galperin | [email protected] | [falko17](https://github.com/falko17) |
121+
122+
123+
[ACE-OAuth]: https://www.ietf.org/archive/id/draft-ietf-ace-oauth-authz-46.html

analysis_options.yaml

Lines changed: 111 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,111 @@
1+
# This file configures the static analysis results for your project (errors,
2+
# warnings, and lints).
3+
#
4+
# This enables the 'recommended' set of lints from `package:lints`.
5+
# This set helps identify many issues that may lead to problems when running
6+
# or consuming Dart code, and enforces writing Dart using a single, idiomatic
7+
# style and format.
8+
9+
include: package:lints/recommended.yaml
10+
11+
# For more information about the core and recommended set of lints, see
12+
# https://dart.dev/go/core-lints
13+
14+
# For additional information about configuring this file, see
15+
# https://dart.dev/guides/language/analysis-options
16+
17+
analyzer:
18+
exclude:
19+
- "**/*.g.dart"
20+
- "**/*.freezed.dart"
21+
strong-mode:
22+
implicit-casts: false
23+
implicit-dynamic: false
24+
errors:
25+
invalid_annotation_target: ignore # for freezed
26+
missing_required_param: warning
27+
missing_return: warning
28+
package_api_docs: warning
29+
public_member_api_docs: warning
30+
prefer_interpolation_to_compose_strings: warning
31+
unnecessary_lambdas: warning
32+
avoid_catches_without_on_clauses: warning
33+
avoid_catching_errors: warning
34+
prefer_mixin: warning
35+
use_setters_to_change_properties: warning
36+
avoid_setters_without_getters: warning
37+
type_annotate_public_apis: warning
38+
always_declare_return_types: warning
39+
avoid_void_async: warning
40+
only_throw_errors: warning
41+
prefer_final_locals: warning
42+
prefer_null_aware_method_calls: warning
43+
unawaited_futures: warning
44+
depend_on_referenced_packages: warning
45+
flutter_style_todos: info
46+
deprecated_member_use_from_same_package: info
47+
todo: ignore
48+
49+
# Rules in addition to recommended set
50+
linter:
51+
rules:
52+
- directives_ordering
53+
- package_api_docs
54+
- public_member_api_docs
55+
- comment_references
56+
- prefer_interpolation_to_compose_strings
57+
- unnecessary_lambdas
58+
- lines_longer_than_80_chars
59+
- avoid_catches_without_on_clauses # no pokémon exception handling (at least only catch Exception)
60+
- avoid_catching_errors
61+
- use_to_and_as_if_applicable # this rule may cause false positives, if so, just disable it
62+
- prefer_mixin
63+
- use_setters_to_change_properties
64+
- avoid_setters_without_getters # use a method instead
65+
- avoid_returning_this # use cascades instead
66+
- type_annotate_public_apis
67+
- avoid_types_on_closure_parameters
68+
- avoid_positional_boolean_parameters
69+
- avoid_dynamic_calls
70+
- avoid_returning_null_for_future
71+
- avoid_slow_async_io
72+
- cancel_subscriptions
73+
- close_sinks
74+
- always_declare_return_types
75+
- avoid_void_async
76+
- cascade_invocations
77+
- eol_at_end_of_file
78+
- flutter_style_todos
79+
- leading_newlines_in_multiline_strings
80+
- only_throw_errors
81+
- prefer_final_locals
82+
- prefer_null_aware_method_calls
83+
- unawaited_futures
84+
- unnecessary_null_aware_assignments
85+
- use_if_null_to_convert_nulls_to_bools
86+
- use_is_even_rather_than_modulo
87+
- depend_on_referenced_packages
88+
89+
90+
dart_code_metrics:
91+
anti-patterns:
92+
- long-method
93+
- long-parameter-list
94+
metrics:
95+
cyclomatic-complexity: 20
96+
maximum-nesting-level: 5
97+
number-of-parameters: 4
98+
source-lines-of-code: 50
99+
metrics-exclude:
100+
- test/**
101+
rules:
102+
- avoid-nested-conditional-expressions:
103+
- acceptable-level: 2
104+
- avoid-throw-in-catch-block # throwWithStackTrace should be used instead
105+
- avoid-unnecessary-type-casts
106+
- no-boolean-literal-compare
107+
- no-empty-block
108+
- no-equal-then-else
109+
- no-magic-number:
110+
- allowed: [3.14, -1, 0, 1, 2, 3, 4, 5, 6, 8, 9, 10, 100]
111+
- prefer-correct-type-name

0 commit comments

Comments
 (0)