-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
chore: add example to frontier and publish frontier package
- Loading branch information
1 parent
d2da441
commit 243a249
Showing
13 changed files
with
543 additions
and
29 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,9 @@ | ||
# Changelog | ||
|
||
## 1.0.0 | ||
|
||
- First stable release, providing a clean API for using authentication and authorization strategies in Dart built with frontier_strategy. | ||
|
||
## 0.0.1 | ||
|
||
- Initial version. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
# https://dart.dev/guides/libraries/private-files | ||
# Created by `dart pub` | ||
.dart_tool/ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
## 1.0.0 | ||
|
||
- Initial version. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
A sample command-line application with an entrypoint in `bin/`, library code | ||
in `lib/`, and example unit test in `test/`. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
# This file configures the static analysis results for your project (errors, | ||
# warnings, and lints). | ||
# | ||
# This enables the 'recommended' set of lints from `package:lints`. | ||
# This set helps identify many issues that may lead to problems when running | ||
# or consuming Dart code, and enforces writing Dart using a single, idiomatic | ||
# style and format. | ||
# | ||
# If you want a smaller set of lints you can change this to specify | ||
# 'package:lints/core.yaml'. These are just the most critical lints | ||
# (the recommended set includes the core lints). | ||
# The core lints are also what is used by pub.dev for scoring packages. | ||
|
||
include: package:lints/recommended.yaml | ||
|
||
# Uncomment the following section to specify additional rules. | ||
|
||
# linter: | ||
# rules: | ||
# - camel_case_types | ||
|
||
# analyzer: | ||
# exclude: | ||
# - path/to/excluded/files/** | ||
|
||
# For more information about the core and recommended set of lints, see | ||
# https://dart.dev/go/core-lints | ||
|
||
# For additional information about configuring this file, see | ||
# https://dart.dev/guides/language/analysis-options |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,52 @@ | ||
import 'dart:io'; | ||
|
||
import 'package:frontier/frontier.dart'; | ||
|
||
final class HeaderOptions extends StrategyOptions { | ||
final String key; | ||
final String value; | ||
|
||
HeaderOptions({required this.key, required this.value}); | ||
} | ||
|
||
class HeaderStrategy extends Strategy<HeaderOptions> { | ||
HeaderStrategy(super.options, super.callback); | ||
|
||
@override | ||
String get name => 'Header'; | ||
|
||
@override | ||
Future<void> authenticate(StrategyRequest request) async { | ||
callback.call(options, request.headers[options.key] == options.value, done); | ||
} | ||
} | ||
|
||
void main() { | ||
final frontier = Frontier(); | ||
|
||
frontier.use(HeaderStrategy(HeaderOptions(key: 'auth', value: 'admin'), | ||
(options, result, done) async { | ||
done(result); | ||
})); | ||
|
||
final server = HttpServer.bind(InternetAddress.loopbackIPv4, 8080); | ||
|
||
server.then((server) { | ||
server.listen((HttpRequest request) async { | ||
final headers = <String, String>{}; | ||
request.headers.forEach((key, values) { | ||
headers[key] = values.join(','); | ||
}); | ||
final result = await frontier.authenticate( | ||
'Header', | ||
StrategyRequest(headers: headers), | ||
); | ||
if (result) { | ||
request.response.write('Authenticated'); | ||
} else { | ||
request.response.statusCode = HttpStatus.unauthorized; | ||
request.response.write('Not Authenticated'); | ||
} | ||
}); | ||
}); | ||
} |
Oops, something went wrong.