Compare commits
507 commits
Author | SHA1 | Date | |
---|---|---|---|
|
2ea69f2cde | ||
|
f4abaf2474 | ||
|
7983c9c6a9 | ||
|
bfefacda30 | ||
|
67d5f183c1 | ||
|
3865bd41df | ||
|
b71744869d | ||
|
496d05c05d | ||
|
9ffe9d6b09 | ||
|
b92f821745 | ||
|
432cf59cf8 | ||
|
218e4735dd | ||
|
d18bcef2ca | ||
|
28e355510b | ||
|
562bb5a433 | ||
|
b03a7d74c2 | ||
|
8d2f32b3e8 | ||
|
2153827523 | ||
|
1334de4cf4 | ||
|
46824efee0 | ||
|
7dfa47cfe9 | ||
|
f4f36206b6 | ||
|
37c2720969 | ||
|
802de34a33 | ||
|
00f68a57cc | ||
|
b82a2db9a7 | ||
|
61928f5b12 | ||
|
f636c29fdf | ||
|
b2794f4f0b | ||
|
6c8ca004ba | ||
|
c01e96ddc9 | ||
|
42596c1026 | ||
|
5e25d7729d | ||
|
96984ea7da | ||
|
3ab3a4261c | ||
|
3d04bbb561 | ||
|
a67b75ca52 | ||
|
931695b22e | ||
|
ae41dbf55d | ||
|
2e4e153b4f | ||
|
fadcffdc25 | ||
|
ee9d512c1f | ||
|
dcddc2992a | ||
|
775bae4a61 | ||
|
2d351c1319 | ||
|
4b112cd54b | ||
|
b3f3a263fd | ||
|
5687c693d2 | ||
|
7afe56844e | ||
|
80a8b135c7 | ||
|
0915c48054 | ||
|
11c12fd590 | ||
|
c194fadbc2 | ||
|
62fc87e619 | ||
|
1bd7ecd19b | ||
|
9aab0837cb | ||
|
5833e9df6b | ||
|
2ac0157b4a | ||
|
8d016a5b56 | ||
|
14a3f4027d | ||
|
9157754f72 | ||
|
75688821a7 | ||
|
eab5bca3ec | ||
|
6194185e87 | ||
|
e4775d1ea9 | ||
|
78671dd621 | ||
|
8d6f66abcb | ||
|
84f205845a | ||
|
9bb742dcad | ||
|
c8167753b2 | ||
|
9e34773962 | ||
|
6bf4ad4b9e | ||
|
ea94d33b87 | ||
|
7cbdcb0255 | ||
|
d3df89c0a3 | ||
|
19a7f8316d | ||
|
5ed443ae33 | ||
|
7e42a7e317 | ||
|
cb25da3077 | ||
|
2510b76e80 | ||
|
b5b9412814 | ||
|
4f14264d23 | ||
|
6c71ee34a7 | ||
|
3803fd0ace | ||
|
d9e9fe1c38 | ||
|
b71f350d29 | ||
|
bc5ad58aa5 | ||
|
f482e4dc58 | ||
|
5c19a002b6 | ||
|
6224d359e0 | ||
|
564fc5953c | ||
|
bb093a03f6 | ||
|
3f049465d1 | ||
|
184fd15fba | ||
|
07ea5fe889 | ||
|
5daf5390e5 | ||
|
85eb443f88 | ||
|
3411e16418 | ||
|
c18e0dabb5 | ||
|
094fe740c0 | ||
|
a0ade9d3a3 | ||
|
5a97dc51fc | ||
|
ed0b275479 | ||
|
4ceaf7a338 | ||
|
d57dbae6f9 | ||
|
b39795b67b | ||
|
7e6dc485e9 | ||
|
0b109cadfe | ||
|
d31a07bbab | ||
|
06855d127a | ||
|
9b164c8740 | ||
|
6e48fedf5c | ||
|
ba83f62524 | ||
|
c308e5193a | ||
|
529ab75d94 | ||
|
7aad3e615c | ||
|
205743ed9b | ||
|
3c6d2c2e87 | ||
|
2139ae4422 | ||
|
ab36e7ccac | ||
|
23a8d94cd0 | ||
|
32a7e88d2d | ||
|
2698c4d753 | ||
|
e802de14f1 | ||
|
9ba0092b4f | ||
|
e2c0230900 | ||
|
b76ff8195c | ||
|
d56ae5b139 | ||
|
dff56a5034 | ||
|
6a9eb9e5d6 | ||
|
f00f24899d | ||
|
1727700763 | ||
|
1e3ead968a | ||
|
1362002e8c | ||
|
e1679a5115 | ||
|
5c5aad6da0 | ||
|
5c3120f058 | ||
|
64771fb470 | ||
|
c2cef6c68e | ||
|
630f7c16ec | ||
|
bee328e1c1 | ||
|
196ae6a68c | ||
|
d1bbad88d9 | ||
|
d26c50ae70 | ||
|
2a7be6a886 | ||
|
fe44b0f60b | ||
|
ae3544396c | ||
|
b9b59523ef | ||
|
cc362fb704 | ||
|
ea528abc3d | ||
|
1580cc98e6 | ||
|
613a24c89a | ||
|
c1dbc6ed8a | ||
|
124376e22c | ||
|
8f96e89b41 | ||
|
e9fe8dfe26 | ||
|
6fd8f56b52 | ||
|
d4794dbbd1 | ||
|
cfe1ef8189 | ||
|
4fdd0133a3 | ||
|
cf11cc2d3c | ||
|
52c36cdcc2 | ||
|
a1c65849b9 | ||
|
94d1c5affd | ||
|
85a5c45a13 | ||
|
26c39effec | ||
|
46f5bfb600 | ||
|
0ce4741a49 | ||
|
ae60a4f3e2 | ||
|
84a06843e0 | ||
|
e657b2070d | ||
|
1496d61a1c | ||
|
834406de2d | ||
|
eb6d4e6d10 | ||
|
0ca3eb7e01 | ||
|
3afc91edfa | ||
|
6506a3e0de | ||
|
e78f68487d | ||
|
21bc260ec3 | ||
|
a51d09eab0 | ||
|
4cca844b89 | ||
|
65ce31a8cf | ||
|
0285cdbd74 | ||
|
fc5fb9aea7 | ||
|
811e68de70 | ||
|
799f94bb60 | ||
|
c29c7b7049 | ||
|
630c527381 | ||
|
4dcf6883d0 | ||
|
bfd05b6854 | ||
|
393281c903 | ||
|
131a60467b | ||
|
dc5600a9cb | ||
|
df3f3dfd02 | ||
|
113c1b7cd4 | ||
|
d6960acfbf | ||
|
b83adcd51a | ||
|
6772ebbf31 | ||
|
d0363fd6fe | ||
|
ab66012ef1 | ||
|
048f06bc42 | ||
|
b52e5aed39 | ||
|
f59b309327 | ||
|
a806d7c6db | ||
|
8e251e553a | ||
|
1e616f3f5c | ||
|
4ebb63c5f7 | ||
|
1d00088d89 | ||
|
764829b01a | ||
|
adf380dc54 | ||
|
e5743b95e2 | ||
|
7f3eba8538 | ||
|
f2c9ab23eb | ||
|
82b78fdaef | ||
|
d440ebd649 | ||
|
dad2106021 | ||
|
79b3417fcc | ||
|
435fbe4e1a | ||
|
a1f0512f5a | ||
|
97e9c6caf1 | ||
|
7a9362fc56 | ||
|
981397791a | ||
|
85e7463afc | ||
|
f3a1ede6fb | ||
|
2933dbc191 | ||
|
3f77318e80 | ||
|
f89d15b1f4 | ||
|
b8475b01b8 | ||
|
b2618316ef | ||
|
1301b492f7 | ||
|
fb99b0b4ec | ||
|
7ed8589754 | ||
|
c2191a8c9c | ||
|
16bf2ddfc6 | ||
|
9626cc93a4 | ||
|
1f0e61958f | ||
|
193fa6c94a | ||
|
2058e4b2f1 | ||
|
5ce990ccbf | ||
|
c96454fab1 | ||
|
22d3c29857 | ||
|
ae5a714d9c | ||
|
9d8c5ae2f1 | ||
|
c6ca7b4e65 | ||
|
cc7e3a255e | ||
|
71b7d54763 | ||
|
d034fcebe8 | ||
|
83873d0fb7 | ||
|
168c51074b | ||
|
bdf7d33c54 | ||
|
7575a561bb | ||
|
c307147780 | ||
|
0d969aa7f9 | ||
|
966622ed2f | ||
|
95f425021a | ||
|
fcadbd4ccb | ||
|
fd5f726e2f | ||
|
5634447337 | ||
|
f51171faa8 | ||
|
0d4c90a129 | ||
|
9290bce457 | ||
|
a2fafe6d8e | ||
|
08ba4f0609 | ||
|
0905afecbd | ||
|
05cbd71248 | ||
|
342a5a4ac9 | ||
|
ec68a78c1d | ||
|
9b85007072 | ||
|
bddd9fbfb8 | ||
|
87910959fa | ||
|
55ecadce60 | ||
|
f5735ad919 | ||
|
ac1aa898f0 | ||
|
86538f7af1 | ||
|
7809c72f03 | ||
|
14a7b82616 | ||
|
959078fa95 | ||
|
2c74a1d158 | ||
|
f777776df0 | ||
|
c83ba22439 | ||
|
359ed6bf47 | ||
|
4a3b354c92 | ||
|
fecead4a90 | ||
|
a7c750e70f | ||
|
cf8d9814e8 | ||
|
56e0e7a05a | ||
|
d3c672823a | ||
|
0fa22e65e4 | ||
|
bfc94d94eb | ||
|
529d2d20ad | ||
|
1f5e12a8cf | ||
|
8c48be9f9f | ||
|
b9b0e49fd0 | ||
|
5e658703fa | ||
|
6a33545037 | ||
|
6a7e251fee | ||
|
681e91d024 | ||
|
b0d792602a | ||
|
87d446c495 | ||
|
47b658ee3a | ||
|
9a5201b6f0 | ||
|
41167e01bd | ||
|
71b50452ec | ||
|
272363052b | ||
|
5fd3f4d5d2 | ||
|
1708c1f870 | ||
|
308d6df606 | ||
|
6416811dea | ||
|
06d4d4659d | ||
|
43ea7ae60a | ||
|
3fad3ee34b | ||
|
c52bc61e49 | ||
|
52a3a3a3ab | ||
|
ba247bd388 | ||
|
0301b300ad | ||
|
cec05d8c19 | ||
|
729a7740db | ||
|
45218176c7 | ||
|
3fe1778c27 | ||
|
e219b91424 | ||
|
6a34b51f04 | ||
|
2c52e4a5d5 | ||
|
eabe3b3810 | ||
|
1540394586 | ||
|
0043114180 | ||
|
33ba0c69ca | ||
|
7d8677e308 | ||
|
f00d3916f6 | ||
|
5402fa55a9 | ||
|
ba26c88d6b | ||
|
4a48000bc3 | ||
|
5bea55d2c0 | ||
|
3f4ff925dc | ||
|
1560e147cc | ||
|
d1d63ca834 | ||
|
f93f921162 | ||
|
c30609f955 | ||
|
3db9c53fdd | ||
|
98dfef8e33 | ||
|
aff68b2f07 | ||
|
572a134c9c | ||
|
793a8ac115 | ||
|
f0a5e7c6fc | ||
|
a5f4e4ff7a | ||
|
a6681dbdab | ||
|
6c51e7a231 | ||
|
224d2be026 | ||
|
da5b87043d | ||
|
a714059cb9 | ||
|
b185baec7b | ||
|
c96980a887 | ||
|
a226d29514 | ||
|
c89983cb96 | ||
|
a75182565f | ||
|
55c4199b6a | ||
|
1f3dc36604 | ||
|
d28930d3c1 | ||
|
f4ba4fb25c | ||
|
03885543c2 | ||
|
178bc924c1 | ||
|
ae0120398c | ||
|
88643bd6f2 | ||
|
da1faa3ce3 | ||
|
4ba42fca73 | ||
|
d845259edb | ||
|
da49c74f7b | ||
|
1717897b9a | ||
|
2ed19c08cc | ||
|
3cbba10c36 | ||
|
bddc53e0c1 | ||
|
c1755cf156 | ||
|
579cbbfe26 | ||
|
ab2c8d0ad2 | ||
|
38073e5b61 | ||
|
3375d50e68 | ||
|
2ee12efede | ||
|
47cbaacef2 | ||
|
9382529ad7 | ||
|
d33faeacce | ||
|
5f07290573 | ||
|
de299e9c99 | ||
|
28aa31a89b | ||
|
5616303535 | ||
|
99cf7790a4 | ||
|
174388e075 | ||
|
0dc71df45a | ||
|
f5c2598cbd | ||
|
f0255b3cd6 | ||
|
4466926d31 | ||
|
e409e19563 | ||
|
510594d96e | ||
|
49da5f76b1 | ||
|
48a441cf77 | ||
|
6db69d0fb1 | ||
|
ff65e13c75 | ||
|
6d2be10536 | ||
|
8469a05ff0 | ||
|
35bf04b168 | ||
|
dfd974c106 | ||
|
0235039719 | ||
|
f9b07b2477 | ||
|
f28ba22bb4 | ||
|
cd31c040ba | ||
|
bab4e5eaf6 | ||
|
b55489974f | ||
|
2518e36e08 | ||
|
1c1a9de7f5 | ||
|
9637c25a97 | ||
|
abc1153076 | ||
|
d8dcfe8bef | ||
|
8a698f79a7 | ||
|
63b7c53d7f | ||
|
97855f4bf4 | ||
|
9d161b91d4 | ||
|
1c5f0a9d08 | ||
|
7245a45fbe | ||
|
9fa24a64c7 | ||
|
2f6b964807 | ||
|
df52801c66 | ||
|
cad8ae2e60 | ||
|
ac91cde03d | ||
|
339fc08e15 | ||
|
44fc43a9e2 | ||
|
c2faa16768 | ||
|
699e009899 | ||
|
8efc47630e | ||
|
27c79d601e | ||
|
7fbe1c4b7a | ||
|
f7b8d93a23 | ||
|
8adb18662d | ||
|
40b058e0e0 | ||
|
90178066be | ||
|
40542c35cc | ||
|
06d53d6f99 | ||
|
3ffe640033 | ||
|
7d6e869999 | ||
|
a34ce2393c | ||
|
7f82d8b941 | ||
|
399eebc67c | ||
|
a21b5a35e3 | ||
|
3bdee0bb7d | ||
|
1b306aeffe | ||
|
6325185f4e | ||
|
09acfe8a4c | ||
|
5b84a8a124 | ||
|
2c76702e44 | ||
|
9d0fbf9c81 | ||
|
262043861d | ||
|
9db875329d | ||
|
57f4c0d618 | ||
|
03ef2705bd | ||
|
8666997832 | ||
|
af933c3845 | ||
|
c5286ea623 | ||
|
630b301555 | ||
|
342bdb322e | ||
|
e470730990 | ||
|
77a364c446 | ||
|
487d1e0bc7 | ||
|
75fd2fce2a | ||
|
97fb2edf87 | ||
|
127b14bd99 | ||
|
b8499023a2 | ||
|
d8336d26b5 | ||
|
ab6a4895d0 | ||
|
61410f8d9d | ||
|
9b000c768e | ||
|
70e6f1b6c1 | ||
|
2a6536c5c1 | ||
|
2327564d14 | ||
|
b481b6fdf6 | ||
|
9a78563dd6 | ||
|
16ed4bf9a4 | ||
|
72db767c49 | ||
|
2796c0a615 | ||
|
4bacd4d77e | ||
|
9dc5f60379 | ||
|
6ffbdcf442 | ||
|
1e7446af51 | ||
|
ca8e85e60c | ||
|
cf1eef865f | ||
|
8dfc804afb | ||
|
5b52133b55 | ||
|
c679ba2071 | ||
|
437c863aa5 | ||
|
eee6631d73 | ||
|
7c3aa37786 | ||
|
bc070ca798 | ||
|
e9ded9d6b4 | ||
|
33d113e455 | ||
|
9e3e88abe6 | ||
|
e8af46492c | ||
|
6c8789ce34 | ||
|
5221cd244d | ||
|
75890c0efd | ||
|
3500065b96 | ||
|
f1772b3996 | ||
|
d34c335090 | ||
|
f0c629ceb8 | ||
|
5e3abdad74 | ||
|
ad0e6ecf06 | ||
|
1d8fb252be | ||
|
8b2d9bf725 | ||
|
da207f2ddf | ||
|
3db5497480 | ||
|
a8cb77a972 | ||
|
c870b4bab6 |
1225 changed files with 37339 additions and 27078 deletions
224
.cursorrules
Normal file
224
.cursorrules
Normal file
|
@ -0,0 +1,224 @@
|
|||
The name of our company is Protevus
|
||||
The name of our project is Platform
|
||||
Protevus = Laravel and Platform = Illuminate
|
||||
Our Development Langauge is Dart
|
||||
Our cross-platform UI Kit is Flutter
|
||||
Our Implementation is based on Angel3
|
||||
Our Inspiration is based on Laravel
|
||||
Our Deployment Target are Windows, MacOS, Linux, iOS, Android, Web, IoT and Edge Devices
|
||||
|
||||
Protevus Aims to bring a complete Laravel experience to Dart, and Flutter with a truely Unified Full Stack Experience. We aim to mature the platform to support cross-platform development of complex government, military, financial, medical, supply-chain, enterprise and idustrial applications.
|
||||
|
||||
Our 10 Step Development Lifecycle is as follows: We use a hybrid mix of Interface Driven Development, Test Driven Development and AI Software Engineer Agents to assist in generating efficient and reliable code while also providing help with other task like code reviews, documentation, and testing. We call this approach IDD-AI or Individual Driven Developemt AI.
|
||||
|
||||
1. Research - Research the requirements and specifications of the project.
|
||||
2. Identify - Identify the key components and technologies that are needed to build the project. (use opensource)
|
||||
3. Transform - Transform the requirements and specifications from the code to a langauge agnostic abstract contract (YAML)
|
||||
4. Inform - Use the abstract contracts to inform the design of the system and the components.
|
||||
5. Generate - Use AI to generate the initial code based on the abstract contracts.
|
||||
6. Implement - Implement the code in the codebase.
|
||||
7. Test - Test the code to ensure it meets the requirements and specifications.
|
||||
8. Iterate - Iterate the code to improve the design and implementation.
|
||||
9. Review - Review the code to ensure it meets the requirements and specifications.
|
||||
10. Release - Release the code to the public.
|
||||
|
||||
Or RITIGITIRR pronounced Rih-tih-gih-tirr
|
||||
|
||||
The we wash rinse and repeat for each project. When we are done we have a fully functional and robust implementation of the requirements and specifications we will still follow this pattern for enhancements, bug fixes, and new features.
|
||||
|
||||
The API Specifications are in inbox/spec_packagename
|
||||
The Concrete Implementations are in inbox/src_packagename
|
||||
|
||||
The directory structure for the project is as follows:
|
||||
|
||||
config/ = configuration files
|
||||
devops/ = docker and kubernetes configuration
|
||||
docs/ = documentation
|
||||
examples/ = example applications demonstrating using the Platform API
|
||||
packages/ = platform packages
|
||||
resources = images, icons, and other resources
|
||||
scripts/ = utility scripts
|
||||
templates/ = starter templates
|
||||
tests/ = repository wide integration tests
|
||||
tools/ = project wide tools
|
||||
utils/ = cli, console, and other utilities
|
||||
|
||||
Protevus Platform is a hard-fork of Angel3 that is being refactored and rebranded to be Protevus Platform
|
||||
For now all references to Angel3 remain the same, but in the future we will be changing them to Protevus or Platform
|
||||
You must always refer to the project as Platform, not Protevus or Angel3
|
||||
|
||||
You must always prefer leveraging existing sanctioned angel3 packages as dependencies where possible as most of them will be replace and can't be relied on initially.
|
||||
|
||||
You must always prefer leveraging existing standard dart packages as dependencies where possible
|
||||
You will always prefer leveraging any packages that we can from pub.dev or github.com dart/flutter ecosystem
|
||||
|
||||
Our goal is to reimplement the laravel illuminate packages as angel3 packages in short bringing Laravel to Dart
|
||||
Our goal is to reach feature parity with the illuminate api so we must adhere to the specifications of laravel's api as we reimplement the illuminate packages
|
||||
|
||||
We will not reimplement any packages that are not part of laravel, such as symfony packages, or any other packages that are not part of the laravel framework as our goal is to have pure dart implementations so we must find packages in the dart ecosystem where possible or create the feature in dart.
|
||||
|
||||
We will not be re-implementing some features of laravel that would require reinventing wheels, for example angel3's server system is more then sufficiant and consist of the following angel3 packages which we will be initally keeping. Container, Framework, Route Http_Exception, Mock_Request, Modal. All other Illuminate packages will be reimplemented in dart. This list of keepers may change as we begin our phases of development.
|
||||
|
||||
You must always take the following points into consderation when planning and executing your task.
|
||||
|
||||
1. Dart and Flutter ecosystem awareness:
|
||||
- Stay updated with the latest Dart language features and best practices.
|
||||
- Consider Flutter compatibility for components that might be used in mobile/web applications.
|
||||
- Utilize popular Dart packages when appropriate, but be mindful of adding unnecessary dependencies.
|
||||
|
||||
2. Performance considerations:
|
||||
- Implement benchmarking tools to compare performance with both Laravel and the original Angel3.
|
||||
- Use Dart's profiling tools to identify and optimize bottlenecks.
|
||||
- Consider implementing lazy loading and deferred initialization where appropriate.
|
||||
|
||||
3. Asynchronous programming:
|
||||
- Leverage Dart's async/await and Future-based programming extensively.
|
||||
- Implement proper error handling and cancellation for asynchronous operations.
|
||||
- Consider using Streams for reactive programming where appropriate.
|
||||
|
||||
4. Code style and structure:
|
||||
- Follow Dart's official style guide and linting rules.
|
||||
- Implement consistent error handling and logging practices across all packages.
|
||||
- Use Dart's strong typing system to its full potential, including generics and type inference.
|
||||
|
||||
5. Testing strategy:
|
||||
- Implement both unit and integration tests for all components.
|
||||
- Use mock objects and dependency injection to facilitate easier testing.
|
||||
- Implement property-based testing for complex algorithms or data structures.
|
||||
|
||||
6. Documentation:
|
||||
- Use Dart's documentation comments extensively.
|
||||
- Provide examples in documentation for all public APIs.
|
||||
- Create architecture decision records (ADRs) for significant design choices.
|
||||
|
||||
7. Internationalization and localization:
|
||||
- Design with i18n in mind from the start.
|
||||
- Use Dart's intl package for formatting dates, numbers, and plurals.
|
||||
|
||||
8. Error handling and logging:
|
||||
- Implement a consistent error handling strategy across all packages.
|
||||
- Create custom exception classes where appropriate.
|
||||
- Implement structured logging with different log levels.
|
||||
|
||||
9. Security:
|
||||
- Implement security best practices, including input validation, output encoding, and CSRF protection.
|
||||
- Use secure random number generation for cryptographic operations.
|
||||
- Implement rate limiting and throttling mechanisms.
|
||||
|
||||
10. Dependency management:
|
||||
- Use Dart's pub tool effectively for package management.
|
||||
- Consider implementing a monorepo structure for managing multiple packages.
|
||||
|
||||
11. Compatibility layers:
|
||||
- Implement compatibility layers or wrappers to ease migration from Angel3 to the new framework.
|
||||
- Provide migration scripts or tools where possible.
|
||||
|
||||
12. Extensibility:
|
||||
- Design components with extensibility in mind, allowing for easy customization and overriding of default behaviors.
|
||||
- Implement plugin systems where appropriate.
|
||||
|
||||
13. Configuration:
|
||||
- Implement a flexible configuration system that supports different environments (development, testing, production).
|
||||
- Support both file-based and environment variable-based configuration.
|
||||
|
||||
14. CLI tools:
|
||||
- Develop CLI tools to assist in common development tasks (e.g., generating boilerplate code, running migrations).
|
||||
- Ensure CLI tools are cross-platform compatible.
|
||||
|
||||
15. Database abstraction:
|
||||
- Implement database migrations and seeders.
|
||||
- Support multiple database systems, including NoSQL databases.
|
||||
|
||||
16. API design:
|
||||
- Follow RESTful principles when designing APIs.
|
||||
- Consider implementing GraphQL support.
|
||||
|
||||
17. Caching strategies:
|
||||
- Implement various caching mechanisms (in-memory, file-based, distributed).
|
||||
- Provide cache invalidation strategies.
|
||||
|
||||
18. Scalability:
|
||||
- Design components with horizontal scalability in mind.
|
||||
- Implement support for distributed systems and microservices architecture.
|
||||
|
||||
19. Metrics and monitoring:
|
||||
- Implement instrumentation for gathering metrics.
|
||||
- Provide hooks for integrating with monitoring systems.
|
||||
|
||||
20. Dependency injection:
|
||||
- Implement a robust dependency injection system.
|
||||
- Support both constructor and property injection.
|
||||
|
||||
21. Reflection and metadata:
|
||||
- Utilize Dart's reflection capabilities where appropriate.
|
||||
- Implement custom metadata annotations for declarative programming.
|
||||
|
||||
22. Error reporting:
|
||||
- Implement integration with error reporting services (e.g., Sentry).
|
||||
- Provide detailed stack traces and context for errors.
|
||||
|
||||
23. Code generation:
|
||||
- Utilize Dart's build system for code generation where appropriate.
|
||||
- Implement source code generators for repetitive tasks.
|
||||
|
||||
24. Versioning:
|
||||
- Follow semantic versioning principles.
|
||||
- Maintain a detailed changelog.
|
||||
|
||||
25. Community engagement:
|
||||
- Set up issue templates and contribution guidelines on GitHub.
|
||||
- Implement a code of conduct for the project.
|
||||
|
||||
26. Null Safety
|
||||
- Implement sound null safety throughout the entire codebase.
|
||||
- Utilize Dart's null safety features, including:
|
||||
- Nullable and non-nullable types
|
||||
- Late variables
|
||||
- Null-aware operators
|
||||
- Perform null checks where necessary and provide clear documentation on nullability for all public APIs.
|
||||
- Use the `required` keyword for named parameters that must not be null.
|
||||
- Leverage the `?`, `!`, and `??` operators appropriately to handle potential null values.
|
||||
- Implement proper error handling for cases where null values are unexpected.
|
||||
- When interfacing with external code or APIs that are not null-safe:
|
||||
- Use the `dynamic` type or appropriate cast operations cautiously
|
||||
- Utilize the `Never` type for functions that never return normally (i.e., always throw an exception or loop forever).
|
||||
- Consider using the `late` keyword for variables that are initialized after their declaration but before they're used.
|
||||
- When working with collections:
|
||||
- Prefer using nullable item types (e.g., `List<String?>`) over nullable collections (e.g., `List<String>?`) where appropriate
|
||||
- Use static analysis tools to catch potential null safety issues early in the development process.
|
||||
- When migrating existing code:
|
||||
- Use the Dart migration tool
|
||||
- Carefully review all changes
|
||||
- Educate contributors on null safety best practices and include null safety checks in code review processes.
|
||||
|
||||
Here are some notes that you should always keep in mind when working with the project
|
||||
|
||||
Here's the content formatted in Markdown:
|
||||
|
||||
## General Guidelines
|
||||
|
||||
- Always consider the idiomatic Dart approach when implementing Laravel features.
|
||||
- Maintain compatibility with existing Angel3 applications where possible.
|
||||
- Prioritize performance and scalability in all implementations.
|
||||
- Write comprehensive tests for each component, aiming for high code coverage.
|
||||
- Document all public APIs and provide usage examples.
|
||||
- Consider cross-platform compatibility (server, web, mobile) where applicable.
|
||||
- Keep security as a top priority, especially when implementing authentication and encryption features.
|
||||
- Regularly refactor and optimize code as the project progresses.
|
||||
- Engage with the Angel3 community for feedback and contributions throughout the development process.
|
||||
|
||||
## Advanced Implementation Considerations
|
||||
|
||||
- When implementing advanced features like Telescope or Dusk, consider how they can be adapted to work well in a Dart ecosystem.
|
||||
- Pay special attention to how Facades and Macroable traits can be implemented in Dart, as these are core to Laravel's flexibility but may not have direct equivalents in Dart.
|
||||
- For packages like Scout and Passport, research Dart-specific best practices for implementing search and OAuth2 functionalities.
|
||||
- When working on Blade-like templating, consider how to balance between staying close to Blade's syntax and leveraging Dart's language features.
|
||||
|
||||
## Dart-Specific Considerations
|
||||
|
||||
- Always consider the implications of Dart's strong typing when implementing dynamic features from Laravel.
|
||||
- Look for opportunities to leverage Dart's unique features, such as isolates for concurrency, where appropriate.
|
||||
|
||||
The Project Road Map is in @Roadmap Book
|
||||
|
||||
You now have access to all the information that all team members need to start working on the project.
|
6
.devcontainer/devcontainer.json
Normal file
6
.devcontainer/devcontainer.json
Normal file
|
@ -0,0 +1,6 @@
|
|||
{
|
||||
"image": "dart:3.4",
|
||||
"forwardPorts": [3000,5000],
|
||||
"features": {
|
||||
}
|
||||
}
|
1
.fork
Normal file
1
.fork
Normal file
|
@ -0,0 +1 @@
|
|||
Hard-Fork of Angel3 Master Repo 2024-10-01 Advance to Version 9.x
|
3
.github/FUNDING.yml
vendored
3
.github/FUNDING.yml
vendored
|
@ -1,3 +0,0 @@
|
|||
# These are supported funding model platforms
|
||||
|
||||
github: [thosakwe]
|
16
.gitignore
vendored
16
.gitignore
vendored
|
@ -36,6 +36,11 @@ pubspec.lock
|
|||
# Covers JetBrains IDEs: IntelliJ, RubyMine, PhpStorm, AppCode, PyCharm, CLion, Android Studio and Webstorm
|
||||
# Reference: https://intellij-support.jetbrains.com/hc/en-us/articles/206544839
|
||||
|
||||
# If you're building an application, you may want to check-in your pubspec.lock
|
||||
#pubspec.lock
|
||||
pubspec_overrides.yaml
|
||||
pubspec.yaml.bak
|
||||
|
||||
# User-specific stuff:
|
||||
|
||||
## VsCode
|
||||
|
@ -71,8 +76,13 @@ fabric.properties
|
|||
|
||||
# Others
|
||||
logs/
|
||||
*.pem
|
||||
.DS_Store
|
||||
server_log.txt
|
||||
ormapp/
|
||||
backup/
|
||||
backup/
|
||||
|
||||
# ignore protevus platform
|
||||
#wspace/
|
||||
|
||||
# temp
|
||||
#inbox/
|
||||
|
||||
|
|
2
.pubignore
Normal file
2
.pubignore
Normal file
|
@ -0,0 +1,2 @@
|
|||
.DS_Store
|
||||
tasks.json
|
5
.vscode/settings.json
vendored
5
.vscode/settings.json
vendored
|
@ -12,6 +12,7 @@
|
|||
"js": []
|
||||
},
|
||||
"editor.codeActionsOnSave": {
|
||||
"source.fixAll.markdownlint": true
|
||||
}
|
||||
"source.fixAll.markdownlint": "explicit"
|
||||
},
|
||||
"cmake.configureOnOpen": false
|
||||
}
|
40
AUTHORS.md
40
AUTHORS.md
|
@ -1,12 +1,36 @@
|
|||
Primary Authors
|
||||
===============
|
||||
# Protevus Platform Authors
|
||||
|
||||
* __[Thomas Hii](dukefirehawk.apps@gmail.com)__
|
||||
## Core Team
|
||||
|
||||
Thomas is the current maintainer of the code base. He has refactored and migrated the
|
||||
code base to support NNBD.
|
||||
- Patrick Stewart <p.stewart@protevus.com> (Project Lead)
|
||||
- Vacant Spot <jane.smith@example.com> (Lead Developer)
|
||||
- Vacant Spot <bob.johnson@example.com> (Developer)
|
||||
|
||||
* __[Tobe O](thosakwe@gmail.com)__
|
||||
## AI Team
|
||||
- Cody <cody@protevus.com> (AI Coding Assistant)
|
||||
- Claude <claude@protevus.com> (AI Coding Assistant)
|
||||
- Code Copilot <c.copilot@protevus.com> (AI Coding Assistant)
|
||||
- Keymate <keymate@protevus.com> (AI Coding Assistant)
|
||||
|
||||
## Contributors
|
||||
|
||||
- Alice Williams <alice.williams@example.com>
|
||||
- Implemented the ORM module
|
||||
- Contributed to the database abstraction layer
|
||||
|
||||
- Charlie Brown <charlie.brown@example.com>
|
||||
- Implemented the authentication and authorization system
|
||||
- Contributed to the event broadcasting and queueing system
|
||||
|
||||
- Eve Green <eve.green@example.com>
|
||||
- Improved the routing system
|
||||
- Contributed to the middleware implementation
|
||||
|
||||
- Michael Davis <michael.davis@example.com>
|
||||
- Worked on the caching and performance optimization features
|
||||
- Contributed to the documentation
|
||||
|
||||
# Additional contributors (in alphabetical order)
|
||||
|
||||
- Vacant Spot
|
||||
|
||||
Tobe has written much of the original code prior to NNBD migration. He has moved on and
|
||||
is no longer involved with the project.
|
||||
|
|
144
CHANGELOG.md
144
CHANGELOG.md
|
@ -1,144 +0,0 @@
|
|||
# Change Log
|
||||
|
||||
## 4.1.x
|
||||
|
||||
* Refactored the framework internal to use [Belatuk Common Utilities](<https://github.com/dart-backend/belatuk-common-utilities>)
|
||||
* Updated to use `lints` linter
|
||||
* Updated [website](<https://angel3-framework.web.app/>)
|
||||
* Updated [examples](<https://github.com/dart-backend/belatuk-examples>)
|
||||
* Fixed ORM code generator
|
||||
* Fixed Serializer code generator
|
||||
* Fixed graphQL code generator
|
||||
* Fixed CLI
|
||||
* Fixed failed test cases
|
||||
|
||||
## 4.0.0 (NNBD)
|
||||
|
||||
* Published all packages with `angel3_` prefix
|
||||
* Changed Dart SDK requirements for all packages to ">=2.12.0 <3.0.0" to support NNBD.
|
||||
* Migrated pretty_logging to 3.0.0 (0/0 tests passed)
|
||||
* Migrated angel_http_exception to 3.0.0 (0/0 tests passed)
|
||||
* Moved angel_cli to [CLI Repository](<https://github.com/dukefirehawk/cli>) (Not migrated yet)
|
||||
* Added code_buffer and migrated to 2.0.0 (16/16 tests passed)
|
||||
* Added combinator and migrated to 2.0.0 (16/16 tests passed)
|
||||
* Migrated angel_route to 5.0.0 (35/35 tests passed)
|
||||
* Migrated angel_model to 3.0.0 (0/0 tests passed)
|
||||
* Migrated angel_container to 3.0.0 (55/55 tests passed)
|
||||
* Added merge_map and migrated to 2.0.0 (6/6 tests passed)
|
||||
* Added mock_request and migrated to 2.0.0 (5/5 tests)
|
||||
* Migrated angel_framework to 4.0.0 (149/150 tests passed)
|
||||
* Migrated angel_auth to 4.0.0 (31/31 tests passed)
|
||||
* Migrated angel_configuration to 4.0.0 (8/8 testspassed)
|
||||
* Migrated angel_validate to 4.0.0 (7/7 tests passed)
|
||||
* Migrated json_god to 4.0.0 (13/13 tests passed)
|
||||
* Migrated angel_client to 4.0.0 (13/13 tests passed)
|
||||
* Migrated angel_websocket to 4.0.0 (3/3 tests passed)
|
||||
* Migrated angel_test to 4.0.0 (1/1 test passed)
|
||||
* Added symbol_table and migrated to 2.0.0 (16/16 tests passed)
|
||||
* Migrated jael to 4.0.0 (20/20 tests passed)
|
||||
* Migrated jael_preprocessor to 3.0.0 (5/5 tests passed)
|
||||
* Migrated angel_jael to 4.0.0 (1/1 test passed)
|
||||
* Migrated pub_sub to 4.0.0 (16/16 tests passed)
|
||||
* Migrated production to 3.0.0 (0/0 tests passed)
|
||||
* Added html_builder and migrated to 2.0.0 (1/1 tests passed)
|
||||
* Migrated hot to 4.0.0 (0/0 tests passed)
|
||||
* Added range_header and migrated to 3.0.0 (12/12 tests passed)
|
||||
* Migrated angel_static to 4.0.0 (12/12 test passed)
|
||||
* Created basic-sdk-2.12.x_nnbd template (1/1 test passed) <= Milestone 1
|
||||
* Migrated angel_serialize to 4.0.0 (0/0 test passed)
|
||||
* Migrated angel_serialize_generator to 4.0.0 (33/33 tests passed)
|
||||
* Migrated angel_orm to 3.0.0 (0/0 tests passed)
|
||||
* Migrated angel_migration to 3.0.0 (0/0 tests passed)
|
||||
* Added inflection2 and migrated to 1.0.0 (28/32 tests passed)
|
||||
* Migrated angel_orm_generator to 4.0.0 (0/0 tests passed)
|
||||
* Migrated angel_migration_runner to 3.0.0 (0/0 tests passed)
|
||||
* Migrated angel_orm_test to 3.0.0 (0/0 tests passed)
|
||||
* Migrated angel_orm_postgres to 3.0.0 (51/54 tests passed)
|
||||
* Create orm-sdk-2.12.x boilerplate (in progress) <= Milestone 2
|
||||
* Migrated angel_auth_oauth2 to 4.0.0 (0/0 tests passed)
|
||||
* Migrated angel_auth_cache to 4.0.0 (7/7 tests passed)
|
||||
* Migrated angel_auth_cors to 4.0.0 (15/15 tests passed)
|
||||
* Migrated angel_oauth2 to 4.0.0 (17/25 tests passed)
|
||||
* Migrated angel_proxy to 4.0.0 (6/7 tests passed)
|
||||
* Migrated angel_file_service to 4.0.0 (6/6 tests passed)
|
||||
* Migrated graphql_parser to 2.0.0 (55/55 tests passed)
|
||||
* Migrated graphql_schema to 2.0.0 (34/35 tests passed)
|
||||
* Migrated graphql_server to 2.0.0 (9/10 tests passed)
|
||||
* Migrated graphql_generator to 2.0.0 (0/0 tests passed)
|
||||
* Migrated data_loader to 2.0.0 (7/7 tests passed)
|
||||
* Migrated angel_graphql to 2.0.0 (0/0 tests passed)
|
||||
* Migrated angel_mongo to 3.0.0 (0/0 tests passed)
|
||||
* Migrated angel_orm_mysql to 2.0.0 (0/0 tests passed)
|
||||
* Migrated angel_orm_service to 2.0.0 (0/0 tests passed)
|
||||
* Migrated body_parser to 2.0.0 (11/11 tests passed)
|
||||
* Migrated angel_markdown to 3.0.0 (0/0 tests passed)
|
||||
* Migrated angel_jinja to 2.0.0 (0/0 tests passed)
|
||||
* Migrated angel_html to 3.0.0 (1/3 tests passed)
|
||||
* Migrated angel_mustache to 2.0.0 (3/3 tests passed)
|
||||
* Migrated angel_paginate to 3.0.0 (18/18 tests passed)
|
||||
* Migrated angel_poll to 2.0.0 (0/5 tests passed)
|
||||
* Migrated angel_redis to 2.0.0 (0/8 tests passed)
|
||||
* Migrated angel_seeder to 2.0.0 (0/0 tests passed)
|
||||
* Migrated angel_relations to 2.0.0 (0/0 tests passed)
|
||||
* Migrated angel_rethink to 2.0.0 (0/0 tests passed)
|
||||
* Migrated angel_security to 2.0.0 (0/1 tests passed)
|
||||
* Migrated angel_sembast to 2.0.0 (10/10 tests passed)
|
||||
* Migrated angel_sync to 3.0.0 (0/1 tests passed)
|
||||
* Migrated angel_typed_service to 3.0.0 (4/4 tests passed)
|
||||
* Migrated angel_shelf to 2.0.0 (0/1 tests passed)
|
||||
* Migrated user_agent to 2.0.0 (0/0 tests passed)
|
||||
* Migrated angel_user_agent to 2.0.0 (0/0 tests passed)
|
||||
|
||||
## 3.0.0 (Non NNBD)
|
||||
|
||||
* Changed Dart SDK requirements for all packages to ">=2.10.0 <3.0.0"
|
||||
* Updated pretty_logging to 2.0.0 (0/0 tests passed)
|
||||
* Updated angel_http_exception to 2.0.0 (0/0 tests passed)
|
||||
* Updated angel_cli to 3.0.0. (Rename not working)
|
||||
* Updated angel_route to 4.0.0 (35/35 tests passed)
|
||||
* Updated angel_model to 2.0.0 (0/0 tests passed)
|
||||
* Updated angel_container to 2.0.0 (55/55 tests passed)
|
||||
* Updated angel_framework to 3.0.0 (150/151 tests passed)
|
||||
* Updated angel_auth to 3.0.0 (28/32 tests passed)
|
||||
* Updated angel_configuration to 3.0.0 (6/8 tests passed)
|
||||
* Updated angel_validate to 3.0.0 (7/7 tests passed)
|
||||
* Added and updated json_god to 3.0.0 (7/7 tests passed)
|
||||
* Updated angel_client to 3.0.0 (10/13 tests passed)
|
||||
* Updated angel_websocket to 3.0.0 (3/3 tests passed)
|
||||
* Updated jael to 3.0.0 (20/20 tests passed)
|
||||
* Updated jael_preprocessor to 3.0.0 (5/5 tests passed)
|
||||
* Updated test to 3.0.0 (1/1 tests passed)
|
||||
* Updated angel_jael to 3.0.0 (1/1 tests passed, Issue with 2 dependencies)
|
||||
* Added pub_sub and updated to 3.0.0 (16/16 tests passed)
|
||||
* Updated production to 2.0.0 (0/0 tests passed)
|
||||
* Updated hot to 3.0.0 (0/0 tests passed)
|
||||
* Updated static to 3.0.0 (12/12 tests passed)
|
||||
* Update basic-sdk-2.12.x boilerplate (1/1 tests passed)
|
||||
* Updated angel_serialize to 3.0.0 (0/0 tests passed)
|
||||
* Updated angel_serialize_generator to 3.0.0 (33/33 tests passed)
|
||||
* Updated angel_orm to 3.0.0 (0/0 tests passed)
|
||||
* Updated angel_migration to 3.0.0 (0/0 tests passed)
|
||||
* Updated angel_orm_generator to 3.0.0 (0/0 tests passed, use a fork of postgres)
|
||||
* Updated angel_migration_runner to 3.0.0 (0/0 tests passed)
|
||||
* Updated angel_orm_test to 1.0.0 (0/0 tests passed)
|
||||
* Updated angel_orm_postgres to 2.0.0 (52/54 tests passed)
|
||||
* Update orm-sdk-2.12.x boilerplate
|
||||
* Updated angel_auth_oauth2 to 3.0.0 (0/0 tests passed)
|
||||
* Updated angel_auth_cache to 3.0.0 (0/7 tests passed)
|
||||
* Updated angel_auth_cors to 3.0.0 (15/15 tests passed)
|
||||
* Updated angel_oauth2 to 3.0.0 (17/25 tests passed)
|
||||
* Updated angel_container_generator to 2.0.0
|
||||
* Updated angel_file_service to 3.0.0
|
||||
* Updated angel_eventsource to 2.0.0 (use a fork of eventsource)
|
||||
* Updated angel_auth_twitter to 3.0.0 (use a fork of twitter and oauth)
|
||||
|
||||
## 2.2.0
|
||||
|
||||
* Changed Dart SDK requirements for all packages to ">=2.10.0 <2.12.0"
|
||||
* Upgraded 3rd party libraries to the latest version prior to dart 2.12
|
||||
* Fixed broken code due to 3rd party libraries update
|
||||
* Revert packages/validate from version 3.0 to version 2.2
|
||||
|
||||
## 2.1.x and below
|
||||
|
||||
* Refer to the orginal repo before the fork
|
39
CODE_OF_CONDUCT.md
Normal file
39
CODE_OF_CONDUCT.md
Normal file
|
@ -0,0 +1,39 @@
|
|||
# Protevus Platform Code of Conduct
|
||||
|
||||
## Our Pledge
|
||||
|
||||
We, as members, contributors, and leaders of the Protevus Platform community, pledge to make participation in our project and community a harassment-free experience for everyone, regardless of age, body size, visible or invisible disability, ethnicity, sex characteristics, gender identity and expression, level of experience, education, socio-economic status, nationality, personal appearance, race, caste, color, religion, or sexual identity and orientation.
|
||||
|
||||
We pledge to act and interact in ways that contribute to an open, welcoming, diverse, inclusive, and healthy community.
|
||||
|
||||
## Our Standards
|
||||
|
||||
Examples of behavior that contributes to a positive environment for our community include:
|
||||
|
||||
- Using welcoming and inclusive language
|
||||
- Being respectful of differing viewpoints and experiences
|
||||
- Gracefully accepting constructive criticism
|
||||
- Focusing on what is best for the community
|
||||
- Showing empathy towards other community members
|
||||
|
||||
Examples of unacceptable behavior include:
|
||||
|
||||
- The use of sexualized language or imagery, and sexual attention or advances of any kind
|
||||
- Trolling, insulting/derogatory comments, and personal or political attacks
|
||||
- Public or private harassment
|
||||
- Publishing others' private information, such as a physical or electronic address, without explicit permission
|
||||
- Other conduct which could reasonably be considered inappropriate in a professional setting
|
||||
|
||||
## Enforcement Responsibilities
|
||||
|
||||
Community leaders are responsible for clarifying and enforcing our standards of acceptable behavior and will take appropriate and fair corrective action in response to any behavior that they deem inappropriate, threatening, offensive, or harmful.
|
||||
|
||||
Community leaders have the right and responsibility to remove, edit, or reject comments, commits, code, wiki edits, issues, and other contributions that are not aligned with this Code of Conduct, and will communicate reasons for moderation decisions when appropriate.
|
||||
|
||||
## Scope
|
||||
|
||||
This Code of Conduct applies within all community spaces, and also applies when an individual is officially representing the community in public spaces. Examples of representing our community include using an official e-mail address, posting via an official social media account, or acting as an appointed representative at an online or offline event.
|
||||
|
||||
## Enforcement
|
||||
|
||||
Instances of abusive, harassing, or otherwise unacceptable behavior may be reported to the community leaders responsible for enforcement at [insert email
|
|
@ -1,25 +1,71 @@
|
|||
# Contributing to the Protevus Platform
|
||||
|
||||
# Contribution
|
||||
Welcome to the Protevus Platform project! We appreciate your interest in contributing to our open-source application server platform. This document outlines the guidelines and best practices for contributing to the project.
|
||||
|
||||
Any help from the open-source community is always welcome and needed:
|
||||
## Code of Conduct
|
||||
|
||||
1. Found an issue?
|
||||
- Please [fill a bug report][tracker] with error message and steps to reproduce it.
|
||||
2. Wish a feature?
|
||||
- Open a feature request with use cases.
|
||||
3. Are you using and liking the project?
|
||||
- Create an article about your use case
|
||||
- Do a post on your likes and dislikes
|
||||
- Make a donation.
|
||||
4. Are you a developer?
|
||||
- Fix a bug and send a [pull request][pull_request]
|
||||
- Implement a new feature
|
||||
- Improve the Unit Tests
|
||||
- Improve the [User Guide][doc] and send a [document pull request][doc_repo]
|
||||
5. Have you already helped in any way?
|
||||
- **Many thanks to the contributors and everybody that uses this project!**
|
||||
By participating in this project, you are expected to uphold our [Code of Conduct](CODE_OF_CONDUCT.md). Please review it to understand the behavior standards expected of all contributors.
|
||||
|
||||
[tracker]: https://github.com/dukefirehawk/angel/issues
|
||||
[pull_request]: https://github.com/dukefirehawk/angel/pulls
|
||||
[doc]: https://angel3-docs.dukefirehawk.com
|
||||
[doc_repo]: https://github.com/dukefirehawk/angel3-guide/pulls
|
||||
## Ways to Contribute
|
||||
|
||||
There are many ways to contribute to the Protevus Platform project, including:
|
||||
|
||||
- Reporting bugs or issues
|
||||
- Suggesting new features or improvements
|
||||
- Submitting pull requests with bug fixes or new features
|
||||
- Improving documentation
|
||||
- Participating in discussions and providing feedback
|
||||
|
||||
## Getting Started
|
||||
|
||||
1. Fork the repository and create a new branch for your contribution.
|
||||
2. Follow the project's coding standards and conventions.
|
||||
3. Write clear and descriptive commit messages.
|
||||
4. Test your changes locally before submitting a pull request.
|
||||
5. Submit a pull request with a detailed description of your changes.
|
||||
|
||||
## Branching Conventions
|
||||
|
||||
When creating a new branch for your contribution, please follow these naming conventions:
|
||||
|
||||
topic names.
|
||||
```
|
||||
docs/<description>
|
||||
fix/<username>-<description>
|
||||
feature/<username>-<description>
|
||||
refactor/<username>-<description>
|
||||
```
|
||||
|
||||
If the scope of the issue changes for any reason, please create a new branch with the appropriate naming convention.
|
||||
|
||||
## Local Testing
|
||||
|
||||
While we provide CI/CD through GitHub Actions, it is recommended to set up your local testing environment to run tests before pushing commits. Follow the instructions in the project's documentation or the CI configuration files to set up your local testing environment.
|
||||
|
||||
### Running Tests
|
||||
|
||||
Currently, there are three sets of tests that need to be run:
|
||||
|
||||
```bash
|
||||
melos test-unit
|
||||
# These two need to be run inside packages/conduit
|
||||
dart test -j1 test/* # use dart test -j1 for Windows and macOS
|
||||
dart tool/generated_test_runner.dart
|
||||
```
|
||||
The first command will run all the unit tests in the Conduit package and its dependencies. The last two commands test CLI components and string-compiled code, respectively.
|
||||
|
||||
## Pull Request Requirements
|
||||
|
||||
Document the intent and purpose of the pull request.
|
||||
All non-documentation pull requests must include automated tests that cover the new code, including failure cases.
|
||||
If tests work locally but not on the CI, please mention @j4qfrost on the pull request or reach out on the Discord server.
|
||||
|
||||
## Commits and Versioning
|
||||
|
||||
The project uses melos for tooling, which provides autoversioning based on conventional commits. Commits to the master branch will usually be squashed from pull requests, so ensure that the pull request title uses conventional commits to trigger versioning and publishing CI. You do not need to use conventional commits on each commit to your branch.
|
||||
|
||||
## Licensing
|
||||
|
||||
Protevus Platform is released under the [MIT License](LICENSE).
|
||||
|
||||
Thank you for your interest in contributing to the Protevus Platform project! We look forward to your contributions and appreciate your efforts to make this project better.
|
42
LICENSE
42
LICENSE
|
@ -1,29 +1,21 @@
|
|||
BSD 3-Clause License
|
||||
MIT License
|
||||
|
||||
Copyright (c) 2021, dukefirehawk.com
|
||||
All rights reserved.
|
||||
Copyright (c) 2024 Protevus
|
||||
|
||||
Redistribution and use in source and binary forms, with or without
|
||||
modification, are permitted provided that the following conditions are met:
|
||||
Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
of this software and associated documentation files (the "Software"), to deal
|
||||
in the Software without restriction, including without limitation the rights
|
||||
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
copies of the Software, and to permit persons to whom the Software is
|
||||
furnished to do so, subject to the following conditions:
|
||||
|
||||
1. Redistributions of source code must retain the above copyright notice, this
|
||||
list of conditions and the following disclaimer.
|
||||
The above copyright notice and this permission notice shall be included in all
|
||||
copies or substantial portions of the Software.
|
||||
|
||||
2. Redistributions in binary form must reproduce the above copyright notice,
|
||||
this list of conditions and the following disclaimer in the documentation
|
||||
and/or other materials provided with the distribution.
|
||||
|
||||
3. Neither the name of the copyright holder nor the names of its
|
||||
contributors may be used to endorse or promote products derived from
|
||||
this software without specific prior written permission.
|
||||
|
||||
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
|
||||
AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
||||
IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
|
||||
DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
|
||||
FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
|
||||
DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
|
||||
SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
|
||||
CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
|
||||
OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
|
||||
OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||
SOFTWARE.
|
187
README.md
187
README.md
|
@ -1,128 +1,113 @@
|
|||
# Angel3 Framework
|
||||
<p align="center"><a href="https://protevus.com" target="_blank"><img src="https://git.protevus.com/protevus/branding/raw/branch/main/protevus-logo-bg.png"></a></p>
|
||||
|
||||
[![Angel3 Framework](./logo3.png)](https://github.com/dukefirehawk/angel)
|
||||
# Protevus Platform
|
||||
|
||||
[![version](https://img.shields.io/badge/pub-v4.0.0-brightgreen)](https://pub.dartlang.org/packages/framework)
|
||||
[![Null Safety](https://img.shields.io/badge/null-safety-brightgreen)](https://dart.dev/null-safety)
|
||||
[![Gitter](https://img.shields.io/gitter/room/nwjs/nw.js.svg)](https://gitter.im/angel_dart/discussion)
|
||||
Protevus Platform is a highly versatile and extensible application server platform for the Dart programming language. It is a hard fork of the Angel3 framework, inspired by Express.js and Laravel, aiming to provide a familiar and Laravel-compatible API while leveraging the power of Dart.
|
||||
|
||||
[![License](https://img.shields.io/github/license/dukefirehawk/angel)](https://github.com/dukefirehawk/angel/LICENSE)
|
||||
> **Note:** This repository contains the core code of the Protevus Platform. If you want to build an application using Protevus, visit the main [Protevus repository](https://github.com/protevus/protevus).
|
||||
|
||||
**A polished, production-ready backend framework in Dart with NNBD support.**
|
||||
## About Protevus
|
||||
|
||||
-----
|
||||
Protevus Platform allows developers to leverage their existing Laravel knowledge and experience in the Dart ecosystem. It combines the best features of Angel3 with Laravel-inspired design patterns and APIs, creating a powerful and familiar environment for web application development.
|
||||
|
||||
## About
|
||||
## AI Assistance
|
||||
|
||||
Angel3 is a fork of the original Angel framework to support NNBD in Dart SDK 2.12.x and later.
|
||||
It is a full-stack Web framework in Dart that aims to streamline development by providing many common features out-of-the-box in a consistent manner. One of the main goal is to enable developers to build both frontend and backend in the same language, Dart. Angel3 framework is designed as a collection of plugins that enable developers to pick and choose the parts needed for their projects. A series of starter templates are also provided for quick start and trial run with Angel3 framework. Visit our [website](<https://angel3-framework.web.app/>) to learn more.
|
||||
The Protevus Platform project utilizes AI assistance in various aspects of its development process. We believe in leveraging the capabilities of AI to enhance productivity, code quality, and overall project progress while maintaining transparency and adhering to ethical practices.
|
||||
|
||||
The availabe features in Angel3 includes:
|
||||
### AI Tools and Models
|
||||
|
||||
* Static File Handling
|
||||
* Basic Authentication
|
||||
* PostgreSQL ORM
|
||||
* GraphQL
|
||||
* And much more...
|
||||
The following AI tools and models have been primarily employed in the development of the Protevus Platform:
|
||||
|
||||
See all the available [`packages`](https://angel3-docs.dukefirehawk.com/packages) for more information.
|
||||
- **Continue** (continue.dev)
|
||||
- **OpenRouter** (openrouter.ai)
|
||||
- **Claude** (claude.ai)
|
||||
- **Codestral** (mistral.ai)
|
||||
- **Voyage** (voyage.ai)
|
||||
- Other tools and LLMs
|
||||
|
||||
## Important Notes
|
||||
### Guidelines and Limitations
|
||||
|
||||
The core Angel Framework migration to Angel3 Framework has completed and published under `angel3_` prefix on pub.dev. The migrated packages have passed all the test cases. The development work will now move onto the next phase which is to refactor and to improve on the features for better development and deployment experience.
|
||||
While AI assistance has been invaluable in accelerating certain aspects of development, we adhere to strict guidelines to ensure quality, security, and ethical use of AI in our development process.
|
||||
|
||||
The status of the code base is as follows:
|
||||
## Features
|
||||
|
||||
Branch: `master`
|
||||
- **Laravel API Compatibility**: Familiar API for Laravel developers
|
||||
- **Modular Architecture**: Separating core components and libraries
|
||||
- **High Performance**: Leverages Dart's efficient event-driven model and isolates for concurrent processing.
|
||||
- **Asynchronous Processing**: Built on Dart's async-await paradigm for non-blocking operations.
|
||||
- **Extensibility**: Support for custom extensions
|
||||
- **Community-Driven**: Open-source principles and community contributions
|
||||
- **Modular Packages**: Standalone Dart packages for each component
|
||||
- **Comprehensive Routing**: Powerful routing capabilities
|
||||
- **Dependency Injection**: Built-in support
|
||||
- **Middleware Support**: For filtering HTTP requests
|
||||
- **Authentication & Authorization**: Robust tools
|
||||
- **Database Abstraction**: Query builder and ORM
|
||||
- **Queueing System**: Manage background tasks
|
||||
- **Event Broadcasting**: Real-time event capabilities
|
||||
- **Full-Stack Experience**: Server-side views and Flutter support for frontends
|
||||
- **WebSocket Support**: Real-time communication
|
||||
- **ORM and Database Integration**: Work with various database systems
|
||||
- **Templating Engine**: For server-side rendering
|
||||
- **Static File Serving**: Built-in middleware
|
||||
- **Scalability**: Designed to handle multiple concurrent connections efficiently.
|
||||
- **Testing Utilities**: Comprehensive testing support
|
||||
|
||||
* Dart version : 2.12.x and above.
|
||||
* Publish : Yes. Refer to packages with `angel3_` prefix on [pub.dev](https://pub.dev/publishers/dukefirehawk.com/packages).
|
||||
* NNBD Support : Yes
|
||||
* Status : Release
|
||||
* Notes : Use this for PR
|
||||
## Getting Started
|
||||
|
||||
Branch: `angel3`
|
||||
To get started with Protevus Platform, follow these steps:
|
||||
|
||||
* Dart version : 2.12.x and above.
|
||||
* NNBD Support : Yes
|
||||
* Status : Development
|
||||
* Notes : This branch is under active development. Features maybe broken from time to time.
|
||||
1. **Install Dart**: Ensure you have the Dart SDK installed on your system.
|
||||
|
||||
For more details, checkout [Project Status](https://github.com/dukefirehawk/angel/wiki/Project-Status)
|
||||
2. **Create a new project**:
|
||||
- dart create -t console my_protevus_app cd
|
||||
- my_protevus_app
|
||||
|
||||
## Installation and Setup
|
||||
3. **Add Protevus dependencies**: Add the following to your `pubspec.yaml`:
|
||||
```yaml
|
||||
dependencies:
|
||||
protevus_framework: ^1.0.0
|
||||
protevus_configuration: ^1.0.0
|
||||
```
|
||||
4. **Run pub get**:
|
||||
```shell
|
||||
dart pub get
|
||||
```
|
||||
5. **Create your first Protevus application**: Replace the contents of bin/my_protevus_app.dart with:
|
||||
```dart
|
||||
import 'package:protevus_framework/protevus_framework.dart';
|
||||
import 'package:protevus_framework/http.dart';
|
||||
|
||||
### Create a new project by cloning from boilerplate templates
|
||||
void main() async {
|
||||
var app = Protevus();
|
||||
var http = ProtevusHttp(app);
|
||||
|
||||
1. Download and install [Dart](https://dart.dev/get-dart)
|
||||
app.get('/', (req, res) => res.write('Hello, Protevus!'));
|
||||
|
||||
2. Clone one of the following starter projects:
|
||||
* [Angel3 Basic Template](https://github.com/dukefirehawk/boilerplates/tree/angel3-basic)
|
||||
* [Angel3 ORM Template](https://github.com/dukefirehawk/boilerplates/tree/angel3-orm)
|
||||
* [Angel3 Graphql Template](https://github.com/dukefirehawk/boilerplates/tree/angel3-graphql)
|
||||
await http.startServer('localhost', 3000);
|
||||
print('Server listening at http://localhost:3000');
|
||||
}
|
||||
```
|
||||
6. **Run your application**:
|
||||
```shell
|
||||
dart run bin/my_protevus_app.dart
|
||||
```
|
||||
Visit http://localhost:3000 in your browser to see your Protevus app in action!
|
||||
|
||||
3. Run the project in development mode (*hot-reloaded* is enabled on file changes).
|
||||
## Documentation
|
||||
Comprehensive documentation for Protevus Platform is available at protevus.com/docs/platform. The documentation covers installation, configuration, usage, and advanced topics, including guides and examples.
|
||||
|
||||
```bash
|
||||
dart --observe bin/dev.dart
|
||||
```
|
||||
## Plugins and Packages
|
||||
Protevus Platform offers a wide range of official plugins and packages to extend its functionality, building upon the Angel3 ecosystem and introducing new Laravel-inspired components.
|
||||
|
||||
4. Run the project in production mode (*hot-reloaded* is disabled).
|
||||
## Community and Support
|
||||
GitHub Discussions: github.com/protevus/platform/discussions
|
||||
Twitter: @Protevus
|
||||
Contributing
|
||||
We welcome contributions from the community! Please read our CONTRIBUTING.md for guidelines on how to contribute to Protevus Platform.
|
||||
|
||||
```bash
|
||||
dart bin/prod.dart
|
||||
```
|
||||
## License
|
||||
Protevus Platform is open-source software licensed under the MIT license.
|
||||
|
||||
5. Run as docker. Edit and build the image with the provided `Dockerfile` file.
|
||||
|
||||
6. Next, refer to the [developer guide](https://angel3-docs.dukefirehawk.com/) to learn more about Angel3 framework.
|
||||
|
||||
### Create a new project with Angel3 CLI
|
||||
|
||||
1. Download and install [Dart](https://dart.dev/get-dart)
|
||||
|
||||
2. Install the [Angel3 CLI](https://pub.dev/packages/angel3_cli):
|
||||
|
||||
```bash
|
||||
dart pub global activate angel3_cli
|
||||
```
|
||||
|
||||
3. On terminal, create a new project:
|
||||
|
||||
```bash
|
||||
angel3 init hello
|
||||
```
|
||||
|
||||
4. Run the project in development mode (*hot-reloaded* is enabled on file changes).
|
||||
|
||||
```bash
|
||||
dart --observe bin/dev.dart
|
||||
```
|
||||
|
||||
5. Run the project in production mode (*hot-reloaded* is disabled).
|
||||
|
||||
```bash
|
||||
dart bin/prod.dart
|
||||
```
|
||||
|
||||
6. Run as docker. Edit and build the image with the provided `Dockerfile` file.
|
||||
|
||||
7. Next, refer to the [developer guide](https://angel3-docs.dukefirehawk.com/) to learn more about Angel3 framework.
|
||||
|
||||
### Migrating from Angel to Angel3
|
||||
|
||||
Check out [Migrating to Angel3](https://angel3-docs.dukefirehawk.com/migration/angel-2.x.x-to-angel3/migration-guide-3)
|
||||
|
||||
## Examples and Documentation
|
||||
|
||||
Visit the [User Guide](https://angel3-docs.dukefirehawk.com/) for dozens of guides and resources, including video tutorials, to get up and running as quickly as possible with Angel3 framework.
|
||||
|
||||
Examples and complete projects can be found [here](https://github.com/dukefirehawk/angel3-examples).
|
||||
|
||||
You can also view the [Angel3 API](http://www.dartdocs.org/documentation/angel_framework/latest).
|
||||
|
||||
There is also an [Awesome Angel :fire:](https://github.com/dukefirehawk/angel3-awesome) list.
|
||||
|
||||
## Contributing
|
||||
|
||||
Interested in contributing to Angel3? See the contribution guide [here](CONTRIBUTING.md).
|
||||
## Acknowledgements
|
||||
Protevus Platform is built upon the foundation of Angel3 and inspired by Laravel. We'd like to thank the creators and contributors of both these frameworks for their invaluable work in the web development ecosystem.
|
49
SECURITY.md
Normal file
49
SECURITY.md
Normal file
|
@ -0,0 +1,49 @@
|
|||
# Protevus Platform Security
|
||||
|
||||
The Protevus Platform team takes security seriously and is committed to ensuring the security and integrity of the project. This document outlines the security practices, policies, and guidelines followed by the project.
|
||||
|
||||
## Reporting Security Vulnerabilities
|
||||
|
||||
If you discover a security vulnerability within the Protevus Platform, we appreciate your help in disclosing it responsibly. Please follow these steps:
|
||||
|
||||
1. **Do not** create a public issue or disclose the vulnerability publicly.
|
||||
2. Send an email to the Protevus Platform security team at [security@protevus.com](mailto:security@protevus.com) with details about the vulnerability, including:
|
||||
- A brief description of the vulnerability
|
||||
- Steps to reproduce the issue
|
||||
- Any potential impact or consequences
|
||||
- Your contact information (optional)
|
||||
3. The security team will acknowledge your report and work with you to investigate and address the vulnerability.
|
||||
4. Once the vulnerability has been addressed, you will be credited in the release notes and the security advisory.
|
||||
|
||||
We appreciate your cooperation in responsibly disclosing security vulnerabilities, as it helps us maintain the integrity and security of the Protevus Platform.
|
||||
|
||||
## Security Practices
|
||||
|
||||
The Protevus Platform team follows industry-standard security practices to ensure the security and integrity of the project:
|
||||
|
||||
- **Code Reviews**: All code contributions undergo thorough code reviews by the core team to identify and mitigate potential security risks.
|
||||
- **Secure Coding Practices**: The project adheres to secure coding practices, including input validation, output encoding, and protection against common web application vulnerabilities (e.g., XSS, CSRF, SQL injection).
|
||||
- **Dependency Management**: Third-party dependencies are regularly monitored and updated to address known vulnerabilities.
|
||||
- **Security Testing**: The project undergoes regular security testing, including static code analysis, dynamic application security testing (DAST), and penetration testing.
|
||||
- **Secure Development Lifecycle**: The project follows a secure development lifecycle, incorporating security considerations throughout the development process, from design to deployment.
|
||||
|
||||
## Security Advisories
|
||||
|
||||
In the event of a security vulnerability being discovered and addressed, the Protevus Platform team will release a security advisory containing the following information:
|
||||
|
||||
- A description of the vulnerability
|
||||
- Affected versions
|
||||
- Mitigation steps or patches
|
||||
- Credit to the individuals who reported the vulnerability (if desired)
|
||||
|
||||
Security advisories will be published on the project's website and communicated to the community through appropriate channels.
|
||||
|
||||
## Responsible Disclosure
|
||||
|
||||
The Protevus Platform team believes in responsible disclosure of security vulnerabilities. We will work with researchers and security professionals to address vulnerabilities in a timely and responsible manner, ensuring that the necessary fixes and mitigations are in place before publicly disclosing the details of the vulnerability.
|
||||
|
||||
## Conclusion
|
||||
|
||||
The security and integrity of the Protevus Platform are of utmost importance to the project team. We are committed to following industry-standard security practices, responsibly disclosing and addressing vulnerabilities, and maintaining open communication with the community regarding security matters.
|
||||
|
||||
If you have any questions or concerns regarding the security of the Protevus Platform, please contact the security team at [security@protevus.com](mailto:security@protevus.com).
|
15
TODO.md
15
TODO.md
|
@ -1,15 +0,0 @@
|
|||
# Development Blueprint
|
||||
|
||||
## Short Term Goal
|
||||
|
||||
* Update examples
|
||||
* Update User Guide
|
||||
* Performance testing
|
||||
|
||||
## Long Term Goal
|
||||
|
||||
* Optimise Angel3 architecture
|
||||
|
||||
### In Progress
|
||||
|
||||
* Migrate generic packages that has no dependencies on Angel3 to [Common Utilities Repository](<https://github.com/dart-backend/belatuk-common-utilities>). All of these packages operate under the hood with no impact to the application build on Angel3. Updating to newer version of Angel3 packages will automatically upgrade them.
|
30
analysis_options.yaml
Normal file
30
analysis_options.yaml
Normal file
|
@ -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
|
0
packages/orm/angel_migration/mono_pkg.yaml → config/.gitkeep
Executable file → Normal file
0
packages/orm/angel_migration/mono_pkg.yaml → config/.gitkeep
Executable file → Normal file
75
devops/README.md
Normal file
75
devops/README.md
Normal file
|
@ -0,0 +1,75 @@
|
|||
# Protevus Platform DevOps
|
||||
|
||||
This directory contains Docker and Kubernetes configurations for the Protevus Platform. It is organized to support our containerization and orchestration needs across different environments.
|
||||
|
||||
## Directory Structure
|
||||
|
||||
```
|
||||
devops/
|
||||
├── docker/
|
||||
│ ├── Dockerfile
|
||||
│ ├── docker-compose.yml
|
||||
│ └── .dockerignore
|
||||
├── kubernetes/
|
||||
│ ├── deployment.yaml
|
||||
│ ├── service.yaml
|
||||
│ ├── ingress.yaml
|
||||
│ └── configmap.yaml
|
||||
├── scripts/
|
||||
│ ├── docker-build.sh
|
||||
│ ├── docker-push.sh
|
||||
│ ├── k8s-deploy.sh
|
||||
│ └── k8s-rollback.sh
|
||||
└── README.md
|
||||
```
|
||||
|
||||
### docker/
|
||||
|
||||
This directory contains Docker-related files for building and running the Protevus Platform in containers.
|
||||
|
||||
- `Dockerfile`: Defines the container image for the Protevus Platform.
|
||||
- `docker-compose.yml`: Configures multi-container Docker applications for local development.
|
||||
- `.dockerignore`: Specifies which files and directories should be excluded when building Docker images.
|
||||
|
||||
### kubernetes/
|
||||
|
||||
The kubernetes/ directory houses Kubernetes manifests for deploying and managing the Protevus Platform in a Kubernetes cluster.
|
||||
|
||||
- `deployment.yaml`: Defines the deployment configuration for the Protevus Platform.
|
||||
- `service.yaml`: Specifies the service configuration for exposing the platform.
|
||||
- `ingress.yaml`: Configures ingress rules for routing external traffic to the service.
|
||||
- `configmap.yaml`: Stores configuration data that can be consumed by pods.
|
||||
|
||||
### scripts/
|
||||
|
||||
This directory contains utility scripts for Docker and Kubernetes operations.
|
||||
|
||||
- `docker-build.sh`: Script for building Docker images.
|
||||
- `docker-push.sh`: Script for pushing Docker images to a registry.
|
||||
- `k8s-deploy.sh`: Script for deploying the application to a Kubernetes cluster.
|
||||
- `k8s-rollback.sh`: Script for rolling back a Kubernetes deployment.
|
||||
|
||||
## Usage Guidelines
|
||||
|
||||
1. Use the provided scripts in the `scripts/` directory for common Docker and Kubernetes operations.
|
||||
2. Ensure all configuration files are properly parameterized for different environments (dev, staging, production).
|
||||
3. Keep sensitive information (like passwords and API keys) out of these files and use Kubernetes secrets instead.
|
||||
4. Regularly update and test these configurations as the Protevus Platform evolves.
|
||||
|
||||
## Deployment Process
|
||||
|
||||
1. Build the Docker image using `scripts/docker-build.sh`.
|
||||
2. Push the image to the container registry with `scripts/docker-push.sh`.
|
||||
3. Deploy to Kubernetes using `scripts/k8s-deploy.sh`.
|
||||
4. If needed, rollback the deployment using `scripts/k8s-rollback.sh`.
|
||||
|
||||
## Contributing
|
||||
|
||||
When contributing to the DevOps configurations:
|
||||
|
||||
1. Test all changes thoroughly in a non-production environment before applying to production.
|
||||
2. Document any new scripts or significant changes to existing configurations.
|
||||
3. Follow Kubernetes and Docker best practices for security and efficiency.
|
||||
4. Submit a pull request with a clear description of the changes and their purpose.
|
||||
|
||||
For any questions or suggestions regarding the DevOps setup, please contact the Protevus Platform infrastructure team.
|
172
devops/docker/README.md
Normal file
172
devops/docker/README.md
Normal file
|
@ -0,0 +1,172 @@
|
|||
# Docker Services
|
||||
|
||||
The required applications by the framework can be run using the docker compose files provided in this folder.
|
||||
|
||||
## PostreSQL
|
||||
|
||||
### Starting the PostreSQL container
|
||||
|
||||
```bash
|
||||
docker compose -f docker-compose-pg.yml -p pg up -d
|
||||
```
|
||||
|
||||
### Stopping the PostreSQL container
|
||||
|
||||
```bash
|
||||
docker compose -f docker-compose-pg.yml -p pg stop
|
||||
docker compose -f docker-compose-pg.yml -p pg down
|
||||
```
|
||||
|
||||
### Checking the PostreSQL container log
|
||||
|
||||
```bash
|
||||
docker logs docker-pg-1 -f
|
||||
```
|
||||
|
||||
### Running psql
|
||||
|
||||
```bash
|
||||
docker exec -it <container id> /bin/bash
|
||||
psql --username postgres
|
||||
```
|
||||
|
||||
### Create PostgreSQL database, user and grant access
|
||||
|
||||
```sql
|
||||
create database orm_test;
|
||||
create user test with encrypted password 'test123';
|
||||
grant all privileges on database orm_test to test;
|
||||
```
|
||||
|
||||
## MariaDB
|
||||
|
||||
### Starting the MariaDB container
|
||||
|
||||
```bash
|
||||
docker compose -f docker-compose-mariadb.yml -p maria up -d
|
||||
```
|
||||
|
||||
### Stopping the MariaDB container
|
||||
|
||||
```bash
|
||||
docker compose -f docker-compose-mariadb.yml -p maria stop
|
||||
docker compose -f docker-compose-mariadb.yml -p maria down
|
||||
```
|
||||
|
||||
### Checking the MariaDB container log
|
||||
|
||||
```bash
|
||||
docker logs maria-mariadb-1 -f
|
||||
```
|
||||
|
||||
### Create MariaDB database, user and grant access
|
||||
|
||||
```sql
|
||||
create database orm_test;
|
||||
|
||||
-- Granting localhost access only
|
||||
create user 'test'@'localhost' identified by 'test123';
|
||||
grant all privileges on orm_test.* to 'test'@'localhost';
|
||||
|
||||
-- Granting localhost and remote access
|
||||
create user 'test'@'%' identified by 'test123';
|
||||
grant all privileges on orm_test.* to 'test'@'%';
|
||||
```
|
||||
|
||||
## MySQL
|
||||
|
||||
### Starting the MySQL container
|
||||
|
||||
```bash
|
||||
docker compose -f docker-compose-mysql.yml -p mysql up -d
|
||||
```
|
||||
|
||||
### Stopping the MySQL container
|
||||
|
||||
```bash
|
||||
docker compose -f docker-compose-mysql.yml -p mysql stop
|
||||
docker compose -f docker-compose-mysql.yml -p mysql down
|
||||
```
|
||||
|
||||
### Checking the MySQL container log
|
||||
|
||||
```bash
|
||||
docker logs mysql-mysql-1 -f
|
||||
```
|
||||
|
||||
### Create MySQL database, user and grant access
|
||||
|
||||
```sql
|
||||
create database orm_test;
|
||||
|
||||
-- Granting localhost access only
|
||||
create user 'test'@'localhost' identified by 'test123';
|
||||
grant all privileges on orm_test.* to 'test'@'localhost';
|
||||
|
||||
-- Granting localhost and remote access
|
||||
create user 'test'@'%' identified by 'test123';
|
||||
grant all privileges on orm_test.* to 'test'@'%';
|
||||
```
|
||||
|
||||
## MongoDB
|
||||
|
||||
### Starting the MongoDB container
|
||||
|
||||
```bash
|
||||
docker compose -f docker-compose-mongo.yml -p mongo up -d
|
||||
```
|
||||
|
||||
### Stopping the MongoDB container
|
||||
|
||||
```bash
|
||||
docker compose -f docker-compose-mongo.yml -p mongo stop
|
||||
docker compose -f docker-compose-mongo.yml -p mongo down
|
||||
```
|
||||
|
||||
### Checking the MongoDB container log
|
||||
|
||||
```bash
|
||||
docker logs mongo-mongo-1 -f
|
||||
```
|
||||
|
||||
## rethinkDB
|
||||
|
||||
### Starting the rethinkDB container
|
||||
|
||||
```bash
|
||||
docker compose -f docker-compose-rethinkdb.yml -p rethink up -d
|
||||
```
|
||||
|
||||
### Stopping the rethinkDB container
|
||||
|
||||
```bash
|
||||
docker compose -f docker-compose-rethinkdb.yml -p rethink stop
|
||||
docker compose -f docker-compose-rethinkdb.yml -p rethink down
|
||||
```
|
||||
|
||||
### Checking the rethinkDB container log
|
||||
|
||||
```bash
|
||||
docker logs rethink-rethinkdb-1 -f
|
||||
```
|
||||
|
||||
## Redis
|
||||
|
||||
### Starting the Redis container
|
||||
|
||||
```bash
|
||||
docker compose -f docker-compose-redis.yml -p redis up -d
|
||||
```
|
||||
|
||||
### Stopping the Redis container
|
||||
|
||||
```bash
|
||||
docker compose -f docker-compose-redis.yml -p redis stop
|
||||
docker compose -f docker-compose-redis.yml -p redis down
|
||||
```
|
||||
|
||||
### Checking the Redis container log
|
||||
|
||||
```bash
|
||||
docker logs redis-redis-1 -f
|
||||
```
|
19
devops/docker/services/docker-compose-mariadb.yml
Normal file
19
devops/docker/services/docker-compose-mariadb.yml
Normal file
|
@ -0,0 +1,19 @@
|
|||
services:
|
||||
mariadb:
|
||||
image: mariadb:latest
|
||||
restart: "no"
|
||||
ports:
|
||||
- "3306:3306"
|
||||
environment:
|
||||
- MARIADB_ROOT_PASSWORD=Qwerty
|
||||
volumes:
|
||||
- "mariadb:/var/lib/mysql"
|
||||
networks:
|
||||
- appnet
|
||||
|
||||
volumes:
|
||||
mariadb:
|
||||
driver: local
|
||||
|
||||
networks:
|
||||
appnet:
|
37
devops/docker/services/docker-compose-mongo.yml
Normal file
37
devops/docker/services/docker-compose-mongo.yml
Normal file
|
@ -0,0 +1,37 @@
|
|||
services:
|
||||
|
||||
mongo:
|
||||
image: mongo
|
||||
restart: no
|
||||
ports:
|
||||
- 27017:27017
|
||||
environment:
|
||||
MONGO_INITDB_ROOT_USERNAME: root
|
||||
MONGO_INITDB_ROOT_PASSWORD: Qwerty
|
||||
MONGO_INITDB_DATABASE: local
|
||||
volumes:
|
||||
- "mongo:/data/db"
|
||||
networks:
|
||||
- appnet
|
||||
|
||||
mongo-express:
|
||||
image: mongo-express
|
||||
restart: no
|
||||
depends_on:
|
||||
- mongo
|
||||
ports:
|
||||
- 8081:8081
|
||||
environment:
|
||||
ME_CONFIG_MONGODB_ADMINUSERNAME: root
|
||||
ME_CONFIG_MONGODB_ADMINPASSWORD: Qwerty
|
||||
ME_CONFIG_MONGODB_URL: mongodb://root:Qwerty@mongo:27017/
|
||||
ME_CONFIG_BASICAUTH: false
|
||||
networks:
|
||||
- webnet
|
||||
|
||||
volumes:
|
||||
mongo:
|
||||
driver: local
|
||||
|
||||
networks:
|
||||
appnet:
|
19
devops/docker/services/docker-compose-mysql.yml
Normal file
19
devops/docker/services/docker-compose-mysql.yml
Normal file
|
@ -0,0 +1,19 @@
|
|||
services:
|
||||
mysql:
|
||||
image: mysql:latest
|
||||
restart: "no"
|
||||
ports:
|
||||
- "3306:3306"
|
||||
environment:
|
||||
- MYSQL_ROOT_PASSWORD=Qwerty
|
||||
volumes:
|
||||
- "mysql:/var/lib/mysql"
|
||||
networks:
|
||||
- appnet
|
||||
|
||||
volumes:
|
||||
mysql:
|
||||
driver: local
|
||||
|
||||
networks:
|
||||
appnet:
|
31
devops/docker/services/docker-compose-pg.yml
Normal file
31
devops/docker/services/docker-compose-pg.yml
Normal file
|
@ -0,0 +1,31 @@
|
|||
services:
|
||||
pgdb:
|
||||
image: postgres:latest
|
||||
restart: "no"
|
||||
ports:
|
||||
- "5432:5432"
|
||||
environment:
|
||||
- POSTGRES_USER=postgres
|
||||
- POSTGRES_PASSWORD=postgres
|
||||
volumes:
|
||||
- "db:/var/lib/postgresql/data"
|
||||
networks:
|
||||
- appnet
|
||||
|
||||
pgadmin4:
|
||||
image: dpage/pgadmin4:latest
|
||||
restart: "no"
|
||||
ports:
|
||||
- "5050:80"
|
||||
environment:
|
||||
- PGADMIN_DEFAULT_EMAIL=admin@mydomain.com
|
||||
- PGADMIN_DEFAULT_PASSWORD=Qwerty
|
||||
networks:
|
||||
- appnet
|
||||
|
||||
volumes:
|
||||
db:
|
||||
driver: local
|
||||
|
||||
networks:
|
||||
appnet:
|
20
devops/docker/services/docker-compose-redis.yml
Normal file
20
devops/docker/services/docker-compose-redis.yml
Normal file
|
@ -0,0 +1,20 @@
|
|||
services:
|
||||
redis:
|
||||
image: redis:latest
|
||||
restart: "no"
|
||||
ports:
|
||||
- "5432:5432"
|
||||
environment:
|
||||
- POSTGRES_USER=postgres
|
||||
- POSTGRES_PASSWORD=postgres
|
||||
volumes:
|
||||
- "redis:/data"
|
||||
networks:
|
||||
- appnet
|
||||
|
||||
volumes:
|
||||
redis:
|
||||
driver: local
|
||||
|
||||
networks:
|
||||
appnet:
|
19
devops/docker/services/docker-compose-rethinkdb.yml
Normal file
19
devops/docker/services/docker-compose-rethinkdb.yml
Normal file
|
@ -0,0 +1,19 @@
|
|||
services:
|
||||
rethinkdb:
|
||||
image: rethinkdb:latest
|
||||
restart: "no"
|
||||
ports:
|
||||
- "8080:8080"
|
||||
- "28015:28015"
|
||||
- "29015:29015"
|
||||
volumes:
|
||||
- "rethinkdb:/data"
|
||||
networks:
|
||||
- appnet
|
||||
|
||||
volumes:
|
||||
rethinkdb:
|
||||
driver: local
|
||||
|
||||
networks:
|
||||
appnet:
|
0
packages/orm/angel_migration_runner/mono_pkg.yaml → devops/k8s/.gitkeep
Executable file → Normal file
0
packages/orm/angel_migration_runner/mono_pkg.yaml → devops/k8s/.gitkeep
Executable file → Normal file
10
docs/Testing.md
Normal file
10
docs/Testing.md
Normal file
|
@ -0,0 +1,10 @@
|
|||
# Performance Testing
|
||||
|
||||
The performance test can be run with the following tools.
|
||||
|
||||
## WRT
|
||||
|
||||
```bash
|
||||
wrk -t12 -c400 -d30s http://localhost:8080/query?queries=20
|
||||
```
|
||||
This runs a benchmark for 30 seconds, using 12 threads, and keeping 400 HTTP connections open.
|
68
helpers/README.md
Normal file
68
helpers/README.md
Normal file
|
@ -0,0 +1,68 @@
|
|||
|
||||
# Protevus Platform Helpers
|
||||
|
||||
This directory contains various helper functionalities, tools, and utilities for the Protevus Platform. It is organized into subdirectories to maintain a clear structure and separation of concerns.
|
||||
|
||||
## Directory Structure
|
||||
|
||||
```
|
||||
helpers/
|
||||
├── cli/
|
||||
├── console/
|
||||
├── tools/
|
||||
└── utilities/
|
||||
```
|
||||
|
||||
### cli/
|
||||
|
||||
This directory contains command-line interface tools and scripts specific to the Protevus Platform. These are typically used for development, deployment, or maintenance tasks that are run directly from the command line.
|
||||
|
||||
Examples:
|
||||
- Database migration scripts
|
||||
- Code generation tools
|
||||
- Deployment scripts
|
||||
|
||||
### console/
|
||||
|
||||
The console/ directory houses console commands and utilities, similar to Laravel's Artisan commands. These are interactive tools that provide a user-friendly interface for various platform operations.
|
||||
|
||||
Examples:
|
||||
- REPL (Read-Eval-Print Loop) for the Protevus Platform
|
||||
- Interactive configuration tools
|
||||
- Database seeding commands
|
||||
|
||||
### tools/
|
||||
|
||||
This directory is for larger, more complex helper applications or scripts used in development, testing, or deployment of the Protevus Platform. These tools often combine multiple functionalities or interact with external services.
|
||||
|
||||
Examples:
|
||||
- Automated testing suites
|
||||
- Performance profiling tools
|
||||
- Documentation generators
|
||||
|
||||
### utilities/
|
||||
|
||||
The utilities/ directory contains general-purpose utility functions and smaller helper scripts. These are typically reusable across different parts of the platform and provide common functionality.
|
||||
|
||||
Examples:
|
||||
- String manipulation functions
|
||||
- Date and time helpers
|
||||
- File system operations
|
||||
|
||||
## Usage Guidelines
|
||||
|
||||
1. Place new helpers in the appropriate subdirectory based on their purpose and complexity.
|
||||
2. Maintain consistency in naming conventions and file structures within each subdirectory.
|
||||
3. Document each helper, tool, or utility with clear comments and usage examples.
|
||||
4. Update this README when adding new significant helpers or changing the structure.
|
||||
|
||||
## Contributing
|
||||
|
||||
When contributing new helpers:
|
||||
|
||||
1. Ensure your code follows the Protevus Platform coding standards.
|
||||
2. Write tests for your helpers when applicable.
|
||||
3. Update or create documentation for new functionalities.
|
||||
4. Submit a pull request with a clear description of the new helper and its purpose.
|
||||
|
||||
For any questions or suggestions regarding the helpers structure, please contact the Protevus Platform core development team.
|
BIN
logo.png
BIN
logo.png
Binary file not shown.
Before Width: | Height: | Size: 6 KiB |
BIN
logo3.png
BIN
logo3.png
Binary file not shown.
Before Width: | Height: | Size: 16 KiB |
BIN
logo3.xcf
BIN
logo3.xcf
Binary file not shown.
20
melos.yaml
Normal file
20
melos.yaml
Normal file
|
@ -0,0 +1,20 @@
|
|||
name: protevus_platform
|
||||
repository: https://github.com/protevus/platform
|
||||
packages:
|
||||
- core/**
|
||||
- packages/**
|
||||
- sandbox/**
|
||||
- wspace/**
|
||||
- examples/**
|
||||
|
||||
command:
|
||||
version:
|
||||
# Generate commit links in package changelogs.
|
||||
linkToCommits: true
|
||||
# Only allow versioning to happen on main branch.
|
||||
branch: master
|
||||
workspaceChangelog: true
|
||||
|
||||
ide:
|
||||
intellij:
|
||||
enabled: false
|
|
@ -1,21 +0,0 @@
|
|||
MIT License (MIT)
|
||||
|
||||
Copyright (c) 2021 dukefirehawk.com
|
||||
|
||||
Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
of this software and associated documentation files (the "Software"), to deal
|
||||
in the Software without restriction, including without limitation the rights
|
||||
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
copies of the Software, and to permit persons to whom the Software is
|
||||
furnished to do so, subject to the following conditions:
|
||||
|
||||
The above copyright notice and this permission notice shall be included in all
|
||||
copies or substantial portions of the Software.
|
||||
|
||||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||
SOFTWARE.
|
1
packages/auth/.gitignore
vendored
1
packages/auth/.gitignore
vendored
|
@ -69,3 +69,4 @@ com_crashlytics_export_strings.xml
|
|||
crashlytics.properties
|
||||
crashlytics-build.properties
|
||||
fabric.properties
|
||||
.DS_Store
|
||||
|
|
|
@ -1,4 +0,0 @@
|
|||
language: dart
|
||||
dart:
|
||||
- dev
|
||||
- stable
|
|
@ -1,5 +1,44 @@
|
|||
# Change Log
|
||||
|
||||
## 8.2.0
|
||||
|
||||
* Require Dart >= 3.3
|
||||
* Updated `lints` to 4.0.0
|
||||
|
||||
## 8.1.1
|
||||
|
||||
* Updated repository link
|
||||
|
||||
## 8.1.0
|
||||
|
||||
* Updated `lints` to 3.0.0
|
||||
|
||||
## 8.0.0
|
||||
|
||||
* Require Dart >= 3.0
|
||||
* Upgraded `http` to 1.0.0
|
||||
* Fixed failed `successRedirect` test case
|
||||
* Fixed failed `failureRedirect` test case
|
||||
* Fixed failed `login` test case
|
||||
* Fixed failed `force basic` test case
|
||||
* Added `example1` and `example2`
|
||||
|
||||
## 7.0.1
|
||||
|
||||
* Fixed linter warnings
|
||||
|
||||
## 7.0.0
|
||||
|
||||
* Require Dart >= 2.17
|
||||
|
||||
## 6.0.0
|
||||
|
||||
* Require Dart >= 2.16
|
||||
|
||||
## 5.0.0
|
||||
|
||||
* Skipped release
|
||||
|
||||
## 4.1.2
|
||||
|
||||
* Fixed `requireAuthentication` to work correctly with null-safety type
|
||||
|
@ -39,11 +78,11 @@
|
|||
|
||||
## 4.0.0
|
||||
|
||||
* Migrated to support Dart SDK 2.12.x NNBD
|
||||
* Migrated to support Dart >= 2.12 NNBD
|
||||
|
||||
## 3.0.0
|
||||
|
||||
* Migrated to work with Dart SDK 2.12.x Non NNBD
|
||||
* Migrated to work with Dart >= 2.12 Non NNBD
|
||||
|
||||
## 2.1.5+1
|
||||
|
||||
|
@ -96,13 +135,13 @@
|
|||
## 2.0.0
|
||||
|
||||
* Made `AuthStrategy` generic.
|
||||
* `AngelAuth.strategies` is now a `Map<String, AuthStrategy<User>>`.
|
||||
* `ProtevusAuth.strategies` is now a `Map<String, AuthStrategy<User>>`.
|
||||
* Removed `AuthStrategy.canLogout`.
|
||||
* Made `AngelAuthTokenCallback` generic.
|
||||
* Made `ProtevusAuthTokenCallback` generic.
|
||||
|
||||
## 2.0.0-alpha
|
||||
|
||||
* Depend on Dart 2 and Angel 2.
|
||||
* Depend on Dart 2 and Protevus 2.
|
||||
* Remove `dart2_constant`.
|
||||
* Remove `requireAuth`.
|
||||
* Remove `userKey`, instead favoring generic parameters.
|
||||
|
|
|
@ -1,11 +1,11 @@
|
|||
# Angel3 Anthentication
|
||||
# Protevus Anthentication
|
||||
|
||||
![Pub Version (including pre-releases)](https://img.shields.io/pub/v/angel3_auth?include_prereleases)
|
||||
![Pub Version (including pre-releases)](https://img.shields.io/pub/v/protevus_auth?include_prereleases)
|
||||
[![Null Safety](https://img.shields.io/badge/null-safety-brightgreen)](https://dart.dev/null-safety)
|
||||
[![Gitter](https://img.shields.io/gitter/room/angel_dart/discussion)](https://gitter.im/angel_dart/discussion)
|
||||
[![License](https://img.shields.io/github/license/dukefirehawk/angel)](https://github.com/dukefirehawk/angel/tree/master/packages/auth/LICENSE)
|
||||
[![Discord](https://img.shields.io/discord/1060322353214660698)](https://discord.gg/3X6bxTUdCM)
|
||||
[![License](https://img.shields.io/github/license/dart-backend/protevus)](https://github.com/dart-backend/protevus/tree/master/packages/auth/LICENSE)
|
||||
|
||||
A complete authentication plugin for Angel3. Inspired by Passport. More details in the [User Guide](https://angel3-docs.dukefirehawk.com/guides/authentication).
|
||||
A complete authentication plugin for Protevus. Inspired by Passport. More details in the [User Guide](https://protevus-docs.dukefirehawk.com/guides/authentication).
|
||||
|
||||
## Bundled Strategies
|
||||
|
||||
|
@ -14,20 +14,20 @@ A complete authentication plugin for Angel3. Inspired by Passport. More details
|
|||
|
||||
## Example
|
||||
|
||||
Ensure you have read the [User Guide](https://angel3-docs.dukefirehawk.com/guides/authentication).
|
||||
Ensure you have read the [User Guide](https://protevus-docs.dukefirehawk.com/guides/authentication).
|
||||
|
||||
```dart
|
||||
configureServer(Angel app) async {
|
||||
var auth = AngelAuth<User>(
|
||||
configureServer(Protevus app) async {
|
||||
var auth = ProtevusAuth<User>(
|
||||
serializer: (user) => user.id ?? '',
|
||||
deserializer: (id) => fetchAUserByIdSomehow(id)
|
||||
deserializer: (id) => fetchAUserByIdSomehow(id
|
||||
);
|
||||
auth.strategies['local'] = LocalAuthStrategy(...);
|
||||
|
||||
// POST route to handle username+password
|
||||
app.post('/local', auth.authenticate('local'));
|
||||
|
||||
// Using Angel's asynchronous injections, we can parse the JWT
|
||||
// Using Protevus's asynchronous injections, we can parse the JWT
|
||||
// on demand. It won't be parsed until we check.
|
||||
app.get('/profile', ioc((User user) {
|
||||
print(user.description);
|
||||
|
@ -52,13 +52,13 @@ configureServer(Angel app) async {
|
|||
|
||||
## Default Authentication Callback
|
||||
|
||||
A frequent use case within SPA's is opening OAuth login endpoints in a separate window. [`angel3_client`](https://pub.dev/packages/angel3_client) provides a facility for this, which works perfectly with the default callback provided in this package.
|
||||
A frequent use case within SPA's is opening OAuth login endpoints in a separate window. [`protevus_client`](https://pub.dev/packages/protevus_client) provides a facility for this, which works perfectly with the default callback provided in this package.
|
||||
|
||||
```dart
|
||||
configureServer(Angel app) async {
|
||||
configureServer(Protevus app) async {
|
||||
var handler = auth.authenticate(
|
||||
'facebook',
|
||||
AngelAuthOptions(callback: confirmPopupAuthentication()));
|
||||
ProtevusAuthOptions(callback: confirmPopupAuthentication()));
|
||||
app.get('/auth/facebook', handler);
|
||||
|
||||
// Use a comma to try multiple strategies!!!
|
||||
|
@ -75,7 +75,7 @@ configureServer(Angel app) async {
|
|||
}
|
||||
```
|
||||
|
||||
This renders a simple HTML page that fires the user's JWT as a `token` event in `window.opener`. `angel3_client` [exposes this as a Stream](https://pub.dev/documentation/angel3_client/latest/):
|
||||
This renders a simple HTML page that fires the user's JWT as a `token` event in `window.opener`. `protevus_client` [exposes this as a Stream](https://pub.dev/documentation/protevus_client/latest/):
|
||||
|
||||
```dart
|
||||
app.authenticateViaPopup('/auth/google').listen((jwt) {
|
||||
|
|
22
packages/auth/example/client/example_client.http
Normal file
22
packages/auth/example/client/example_client.http
Normal file
|
@ -0,0 +1,22 @@
|
|||
### Load landing page
|
||||
GET http://localhost:3000/ HTTP/1.1
|
||||
|
||||
### login (call_back)
|
||||
POST http://localhost:3000/login HTTP/1.1
|
||||
Content-Type: application/json
|
||||
Authorization: Basic jdoe1:password
|
||||
|
||||
### Success redirect (local)
|
||||
POST http://localhost:3000/login HTTP/1.1
|
||||
Content-Type: application/json
|
||||
Authorization: Basic username:password
|
||||
|
||||
### Failure redirect (local)
|
||||
POST http://localhost:3000/login HTTP/1.1
|
||||
Content-Type: application/json
|
||||
Authorization: Basic password:username
|
||||
|
||||
### Force basic
|
||||
GET http://localhost:3000/hello HTTP/1.1
|
||||
Content-Type: application/json
|
||||
Accept:application/json
|
|
@ -1,11 +1,11 @@
|
|||
import 'dart:async';
|
||||
import 'package:angel3_auth/angel3_auth.dart';
|
||||
import 'package:angel3_framework/angel3_framework.dart';
|
||||
import 'package:angel3_framework/http.dart';
|
||||
import 'package:protevus_auth/protevus_auth.dart';
|
||||
import 'package:protevus_framework/protevus_framework.dart';
|
||||
import 'package:protevus_framework/http.dart';
|
||||
|
||||
void main() async {
|
||||
var app = Angel();
|
||||
var auth = AngelAuth<User>(
|
||||
var app = Protevus();
|
||||
var auth = ProtevusAuth<User>(
|
||||
serializer: (user) => user.id ?? '',
|
||||
deserializer: (id) => fetchAUserByIdSomehow(id));
|
||||
|
||||
|
@ -17,11 +17,12 @@ void main() async {
|
|||
// If authentication succeeds, return a User object.
|
||||
//
|
||||
// Otherwise, return `null`.
|
||||
return null;
|
||||
});
|
||||
|
||||
app.post('/auth/local', auth.authenticate('local'));
|
||||
|
||||
var http = AngelHttp(app);
|
||||
var http = ProtevusHttp(app);
|
||||
await http.startServer('127.0.0.1', 3000);
|
||||
|
||||
print('Listening at http://127.0.0.1:3000');
|
||||
|
|
114
packages/auth/example/example1.dart
Normal file
114
packages/auth/example/example1.dart
Normal file
|
@ -0,0 +1,114 @@
|
|||
import 'package:protevus_auth/protevus_auth.dart';
|
||||
import 'package:protevus_container/mirrors.dart';
|
||||
import 'package:protevus_framework/protevus_framework.dart';
|
||||
import 'package:protevus_framework/http.dart';
|
||||
import 'package:collection/collection.dart' show IterableExtension;
|
||||
import 'package:io/ansi.dart';
|
||||
import 'package:logging/logging.dart';
|
||||
import 'package:collection/collection.dart';
|
||||
|
||||
class User extends Model {
|
||||
String? username, password;
|
||||
|
||||
User({this.username, this.password});
|
||||
|
||||
static User parse(Map<String, dynamic> map) {
|
||||
return User(
|
||||
username: map['username'],
|
||||
password: map['password'],
|
||||
);
|
||||
}
|
||||
|
||||
Map<String, dynamic> toJson() {
|
||||
return {
|
||||
'id': id,
|
||||
'username': username,
|
||||
'password': password,
|
||||
'created_at': createdAt?.toIso8601String(),
|
||||
'updated_at': updatedAt?.toIso8601String()
|
||||
};
|
||||
}
|
||||
}
|
||||
|
||||
/*
|
||||
* Backend for callback test cases
|
||||
*/
|
||||
void main() async {
|
||||
hierarchicalLoggingEnabled = true;
|
||||
|
||||
Protevus app = Protevus(reflector: MirrorsReflector());
|
||||
ProtevusHttp angelHttp = ProtevusHttp(app);
|
||||
app.use('/users', MapService());
|
||||
|
||||
var oldErrorHandler = app.errorHandler;
|
||||
app.errorHandler = (e, req, res) {
|
||||
app.logger.severe(e.message, e, e.stackTrace ?? StackTrace.current);
|
||||
return oldErrorHandler(e, req, res);
|
||||
};
|
||||
|
||||
app.logger = Logger('protevus_auth')
|
||||
..level = Level.FINEST
|
||||
..onRecord.listen((rec) {
|
||||
print(rec);
|
||||
|
||||
if (rec.error != null) {
|
||||
print(yellow.wrap(rec.error.toString()));
|
||||
}
|
||||
|
||||
if (rec.stackTrace != null) {
|
||||
print(yellow.wrap(rec.stackTrace.toString()));
|
||||
}
|
||||
});
|
||||
|
||||
await app
|
||||
.findService('users')
|
||||
?.create({'username': 'jdoe1', 'password': 'password'});
|
||||
|
||||
var auth = ProtevusAuth<User>(
|
||||
serializer: (u) => u.id ?? '',
|
||||
deserializer: (id) async =>
|
||||
await app.findService('users')?.read(id) as User);
|
||||
//auth.serializer = (u) => u.id;
|
||||
//auth.deserializer =
|
||||
// (id) async => await app.findService('users')!.read(id) as User;
|
||||
|
||||
await app.configure(auth.configureServer);
|
||||
|
||||
auth.strategies['local'] = LocalAuthStrategy((username, password) async {
|
||||
var users = await app
|
||||
.findService('users')
|
||||
?.index()
|
||||
.then((it) => it.map<User>((m) => User.parse(m)).toList());
|
||||
|
||||
var result = users?.firstWhereOrNull(
|
||||
(user) => user.username == username && user.password == password);
|
||||
|
||||
return Future.value(result);
|
||||
}, allowBasic: true);
|
||||
|
||||
app.post(
|
||||
'/login',
|
||||
auth.authenticate('local',
|
||||
ProtevusAuthOptions(callback: (req, res, token) {
|
||||
res
|
||||
..write('Hello!')
|
||||
..close();
|
||||
})));
|
||||
|
||||
app.get('/', (req, res) => res.write("Hello"));
|
||||
|
||||
app.chain([
|
||||
(req, res) {
|
||||
if (!req.container!.has<User>()) {
|
||||
req.container!.registerSingleton<User>(
|
||||
User(username: req.params['name']?.toString()));
|
||||
}
|
||||
return true;
|
||||
}
|
||||
]).post(
|
||||
'/existing/:name',
|
||||
auth.authenticate('local'),
|
||||
);
|
||||
|
||||
await angelHttp.startServer('127.0.0.1', 3000);
|
||||
}
|
69
packages/auth/example/example2.dart
Normal file
69
packages/auth/example/example2.dart
Normal file
|
@ -0,0 +1,69 @@
|
|||
import 'dart:async';
|
||||
import 'package:protevus_auth/protevus_auth.dart';
|
||||
import 'package:protevus_container/mirrors.dart';
|
||||
import 'package:protevus_framework/protevus_framework.dart';
|
||||
import 'package:protevus_framework/http.dart';
|
||||
import 'package:logging/logging.dart';
|
||||
|
||||
final Map<String, String> sampleUser = {'hello': 'world'};
|
||||
|
||||
final ProtevusAuth<Map<String, String>> auth =
|
||||
ProtevusAuth<Map<String, String>>(
|
||||
serializer: (user) async => '1337',
|
||||
deserializer: (id) async => sampleUser);
|
||||
//var headers = <String, String>{'accept': 'application/json'};
|
||||
var localOpts = ProtevusAuthOptions<Map<String, String>>(
|
||||
failureRedirect: '/failure', successRedirect: '/success');
|
||||
var localOpts2 =
|
||||
ProtevusAuthOptions<Map<String, String>>(canRespondWithJson: false);
|
||||
|
||||
Future<Map<String, String>> verifier(String? username, String? password) async {
|
||||
if (username == 'username' && password == 'password') {
|
||||
return sampleUser;
|
||||
} else {
|
||||
return {};
|
||||
}
|
||||
}
|
||||
|
||||
Future wireAuth(Protevus app) async {
|
||||
//auth.strategies['local'] = LocalAuthStrategy(verifier);
|
||||
auth.strategies['local'] =
|
||||
LocalAuthStrategy(verifier, forceBasic: true, realm: 'test');
|
||||
await app.configure(auth.configureServer);
|
||||
}
|
||||
|
||||
/*
|
||||
* Backend for local test cases
|
||||
*/
|
||||
void main() async {
|
||||
Protevus app = Protevus(reflector: MirrorsReflector());
|
||||
ProtevusHttp angelHttp = ProtevusHttp(app, useZone: false);
|
||||
await app.configure(wireAuth);
|
||||
|
||||
app.get('/hello', (req, res) {
|
||||
// => 'Woo auth'
|
||||
return 'Woo auth';
|
||||
}, middleware: [auth.authenticate('local', localOpts2)]);
|
||||
|
||||
app.post('/login', (req, res) => 'This should not be shown',
|
||||
middleware: [auth.authenticate('local', localOpts)]);
|
||||
|
||||
app.get('/success', (req, res) => 'yep', middleware: [
|
||||
requireAuthentication<Map<String, String>>(),
|
||||
]);
|
||||
|
||||
app.get('/failure', (req, res) => 'nope');
|
||||
|
||||
app.logger = Logger('local_test')
|
||||
..onRecord.listen((rec) {
|
||||
print(
|
||||
'${rec.time}: ${rec.level.name}: ${rec.loggerName}: ${rec.message}');
|
||||
|
||||
if (rec.error != null) {
|
||||
print(rec.error);
|
||||
print(rec.stackTrace);
|
||||
}
|
||||
});
|
||||
|
||||
await angelHttp.startServer('127.0.0.1', 3000);
|
||||
}
|
|
@ -1,4 +1,4 @@
|
|||
/// Stand-alone JWT library.
|
||||
library angel3_auth.auth_token;
|
||||
library protevus_auth.auth_token;
|
||||
|
||||
export 'src/auth_token.dart';
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
library angel3_auth;
|
||||
library protevus_auth;
|
||||
|
||||
export 'src/middleware/require_auth.dart';
|
||||
export 'src/strategies/strategies.dart';
|
|
@ -1,5 +1,5 @@
|
|||
import 'dart:collection';
|
||||
import 'package:angel3_framework/angel3_framework.dart';
|
||||
import 'package:protevus_framework/protevus_framework.dart';
|
||||
import 'dart:convert';
|
||||
import 'package:crypto/crypto.dart';
|
||||
import 'package:logging/logging.dart';
|
||||
|
@ -68,7 +68,7 @@ class AuthToken {
|
|||
|
||||
if (split.length != 3) {
|
||||
_log.warning('Invalid JWT');
|
||||
throw AngelHttpException.notAuthenticated(message: 'Invalid JWT.');
|
||||
throw ProtevusHttpException.notAuthenticated(message: 'Invalid JWT.');
|
||||
}
|
||||
|
||||
var payloadString = decodeBase64(split[1]);
|
||||
|
@ -81,17 +81,17 @@ class AuthToken {
|
|||
|
||||
if (split.length != 3) {
|
||||
_log.warning('Invalid JWT');
|
||||
throw AngelHttpException.notAuthenticated(message: 'Invalid JWT.');
|
||||
throw ProtevusHttpException.notAuthenticated(message: 'Invalid JWT.');
|
||||
}
|
||||
|
||||
// var headerString = decodeBase64(split[0]);
|
||||
var payloadString = decodeBase64(split[1]);
|
||||
var data = split[0] + '.' + split[1];
|
||||
var data = '${split[0]}.${split[1]}';
|
||||
var signature = base64Url.encode(hmac.convert(data.codeUnits).bytes);
|
||||
|
||||
if (signature != split[2]) {
|
||||
_log.warning('JWT payload does not match hashed version');
|
||||
throw AngelHttpException.notAuthenticated(
|
||||
throw ProtevusHttpException.notAuthenticated(
|
||||
message: 'JWT payload does not match hashed version.');
|
||||
}
|
||||
|
||||
|
@ -102,9 +102,9 @@ class AuthToken {
|
|||
String serialize(Hmac hmac) {
|
||||
var headerString = base64Url.encode(json.encode(_header).codeUnits);
|
||||
var payloadString = base64Url.encode(json.encode(toJson()).codeUnits);
|
||||
var data = headerString + '.' + payloadString;
|
||||
var data = '$headerString.$payloadString';
|
||||
var signature = hmac.convert(data.codeUnits).bytes;
|
||||
return data + '.' + base64Url.encode(signature);
|
||||
return '$data.${base64Url.encode(signature)}';
|
||||
}
|
||||
|
||||
Map<String, dynamic> toJson() {
|
||||
|
|
|
@ -1,9 +1,9 @@
|
|||
import 'dart:async';
|
||||
import 'package:angel3_framework/angel3_framework.dart';
|
||||
import 'package:protevus_framework/protevus_framework.dart';
|
||||
|
||||
/// Forces Basic authentication over the requested resource, with the given [realm] name, if no JWT is present.
|
||||
///
|
||||
/// [realm] defaults to `'angel3_auth'`.
|
||||
/// [realm] defaults to `'protevus_auth'`.
|
||||
RequestHandler forceBasicAuth<User>({String? realm}) {
|
||||
return (RequestContext req, ResponseContext res) async {
|
||||
if (req.container != null) {
|
||||
|
@ -17,7 +17,7 @@ RequestHandler forceBasicAuth<User>({String? realm}) {
|
|||
}
|
||||
|
||||
res.headers['www-authenticate'] = 'Basic realm="${realm ?? 'angel_auth'}"';
|
||||
throw AngelHttpException.notAuthenticated();
|
||||
throw ProtevusHttpException.notAuthenticated();
|
||||
};
|
||||
}
|
||||
|
||||
|
@ -25,10 +25,10 @@ RequestHandler forceBasicAuth<User>({String? realm}) {
|
|||
RequestHandler requireAuthentication<User>() {
|
||||
return (RequestContext req, ResponseContext res,
|
||||
{bool throwError = true}) async {
|
||||
bool _reject(ResponseContext res) {
|
||||
bool reject(ResponseContext res) {
|
||||
if (throwError) {
|
||||
res.statusCode = 403;
|
||||
throw AngelHttpException.forbidden();
|
||||
throw ProtevusHttpException.forbidden();
|
||||
} else {
|
||||
return false;
|
||||
}
|
||||
|
@ -42,10 +42,10 @@ RequestHandler requireAuthentication<User>() {
|
|||
await reqContainer.makeAsync<User>();
|
||||
return true;
|
||||
} else {
|
||||
return _reject(res);
|
||||
return reject(res);
|
||||
}
|
||||
} else {
|
||||
return _reject(res);
|
||||
return reject(res);
|
||||
}
|
||||
};
|
||||
}
|
||||
|
|
|
@ -1,17 +1,17 @@
|
|||
import 'dart:async';
|
||||
|
||||
import 'package:angel3_framework/angel3_framework.dart';
|
||||
import 'package:protevus_framework/protevus_framework.dart';
|
||||
import 'auth_token.dart';
|
||||
|
||||
typedef AngelAuthCallback = FutureOr Function(
|
||||
typedef ProtevusAuthCallback = FutureOr Function(
|
||||
RequestContext req, ResponseContext res, String token);
|
||||
|
||||
typedef AngelAuthTokenCallback<User> = FutureOr Function(
|
||||
typedef ProtevusAuthTokenCallback<User> = FutureOr Function(
|
||||
RequestContext req, ResponseContext res, AuthToken token, User user);
|
||||
|
||||
class AngelAuthOptions<User> {
|
||||
AngelAuthCallback? callback;
|
||||
AngelAuthTokenCallback<User>? tokenCallback;
|
||||
class ProtevusAuthOptions<User> {
|
||||
ProtevusAuthCallback? callback;
|
||||
ProtevusAuthTokenCallback<User>? tokenCallback;
|
||||
String? successRedirect;
|
||||
String? failureRedirect;
|
||||
|
||||
|
@ -21,7 +21,7 @@ class AngelAuthOptions<User> {
|
|||
/// Works well with `Basic` authentication.
|
||||
bool canRespondWithJson;
|
||||
|
||||
AngelAuthOptions(
|
||||
ProtevusAuthOptions(
|
||||
{this.callback,
|
||||
this.tokenCallback,
|
||||
this.canRespondWithJson = true,
|
||||
|
|
|
@ -1,7 +1,7 @@
|
|||
import 'dart:async';
|
||||
import 'dart:io';
|
||||
import 'dart:math';
|
||||
import 'package:angel3_framework/angel3_framework.dart';
|
||||
import 'package:protevus_framework/protevus_framework.dart';
|
||||
import 'package:crypto/crypto.dart';
|
||||
import 'package:logging/logging.dart';
|
||||
|
||||
|
@ -9,9 +9,9 @@ import 'auth_token.dart';
|
|||
import 'options.dart';
|
||||
import 'strategy.dart';
|
||||
|
||||
/// Handles authentication within an Angel application.
|
||||
class AngelAuth<User> {
|
||||
final _log = Logger('AngelAuth');
|
||||
/// Handles authentication within an Protevus application.
|
||||
class ProtevusAuth<User> {
|
||||
final _log = Logger('ProtevusAuth');
|
||||
|
||||
late Hmac _hs256;
|
||||
late int _jwtLifeSpan;
|
||||
|
@ -78,7 +78,7 @@ class AngelAuth<User> {
|
|||
}
|
||||
|
||||
/// `jwtLifeSpan` - should be in *milliseconds*.
|
||||
AngelAuth(
|
||||
ProtevusAuth(
|
||||
{String? jwtKey,
|
||||
required this.serializer,
|
||||
required this.deserializer,
|
||||
|
@ -95,29 +95,30 @@ class AngelAuth<User> {
|
|||
_jwtLifeSpan = jwtLifeSpan.toInt();
|
||||
}
|
||||
|
||||
/// Configures an Angel server to decode and validate JSON Web tokens on demand,
|
||||
/// Configures an Protevus server to decode and validate JSON Web tokens on demand,
|
||||
/// whenever an instance of [User] is injected.
|
||||
Future<void> configureServer(Angel app) async {
|
||||
Future<void> configureServer(Protevus app) async {
|
||||
/*
|
||||
if (serializer == null) {
|
||||
throw StateError(
|
||||
'An `AngelAuth` plug-in was called without its `serializer` being set. All authentication will fail.');
|
||||
'An `ProtevusAuth` plug-in was called without its `serializer` being set. All authentication will fail.');
|
||||
}
|
||||
if (deserializer == null) {
|
||||
throw StateError(
|
||||
'An `AngelAuth` plug-in was called without its `deserializer` being set. All authentication will fail.');
|
||||
'An `ProtevusAuth` plug-in was called without its `deserializer` being set. All authentication will fail.');
|
||||
}
|
||||
|
||||
if (app.container == null) {
|
||||
_log.severe('Protevus container is null');
|
||||
throw StateError(
|
||||
'Protevus.container is null. All authentication will fail.');
|
||||
}
|
||||
*/
|
||||
if (app.container == null) {
|
||||
_log.severe('Angel3 container is null');
|
||||
throw StateError(
|
||||
'Angel.container is null. All authentication will fail.');
|
||||
}
|
||||
var appContainer = app.container!;
|
||||
var appContainer = app.container;
|
||||
|
||||
appContainer.registerSingleton(this);
|
||||
if (runtimeType != AngelAuth) {
|
||||
appContainer.registerSingleton(this, as: AngelAuth);
|
||||
if (runtimeType != ProtevusAuth) {
|
||||
appContainer.registerSingleton(this, as: ProtevusAuth);
|
||||
}
|
||||
|
||||
if (!appContainer.has<_AuthResult<User>>()) {
|
||||
|
@ -127,7 +128,7 @@ class AngelAuth<User> {
|
|||
var res = container.make<ResponseContext>();
|
||||
//if (req == null || res == null) {
|
||||
// _log.warning('RequestContext or responseContext is null');
|
||||
// throw AngelHttpException.forbidden();
|
||||
// throw ProtevusHttpException.forbidden();
|
||||
//}
|
||||
|
||||
var result = await _decodeJwt(req, res);
|
||||
|
@ -135,7 +136,7 @@ class AngelAuth<User> {
|
|||
return result;
|
||||
} else {
|
||||
_log.warning('JWT is null');
|
||||
throw AngelHttpException.forbidden();
|
||||
throw ProtevusHttpException.forbidden();
|
||||
}
|
||||
});
|
||||
|
||||
|
@ -183,10 +184,10 @@ class AngelAuth<User> {
|
|||
///
|
||||
/// Now that `package:angel_framework` supports asynchronous injections, this middleware
|
||||
/// is no longer directly necessary. Instead, call [configureServer]. You can then use
|
||||
/// `makeAsync<User>`, or Angel's injections directly:
|
||||
/// `makeAsync<User>`, or Protevus's injections directly:
|
||||
///
|
||||
/// ```dart
|
||||
/// var auth = AngelAuth<User>(...);
|
||||
/// var auth = ProtevusAuth<User>(...);
|
||||
/// await app.configure(auth.configureServer);
|
||||
///
|
||||
/// app.get('/hmm', (User user) async {
|
||||
|
@ -222,7 +223,7 @@ class AngelAuth<User> {
|
|||
if (enforceIp) {
|
||||
if (req.ip != token.ipAddress) {
|
||||
_log.warning('JWT cannot be accessed from this IP address');
|
||||
throw AngelHttpException.forbidden(
|
||||
throw ProtevusHttpException.forbidden(
|
||||
message: 'JWT cannot be accessed from this IP address.');
|
||||
}
|
||||
}
|
||||
|
@ -233,7 +234,7 @@ class AngelAuth<User> {
|
|||
|
||||
if (!expiry.isAfter(DateTime.now())) {
|
||||
_log.warning('Expired JWT');
|
||||
throw AngelHttpException.forbidden(message: 'Expired JWT.');
|
||||
throw ProtevusHttpException.forbidden(message: 'Expired JWT.');
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -307,13 +308,13 @@ class AngelAuth<User> {
|
|||
|
||||
if (jwt == null) {
|
||||
_log.warning('No JWT provided');
|
||||
throw AngelHttpException.forbidden(message: 'No JWT provided');
|
||||
throw ProtevusHttpException.forbidden(message: 'No JWT provided');
|
||||
} else {
|
||||
var token = AuthToken.validate(jwt, _hs256);
|
||||
if (enforceIp) {
|
||||
if (req.ip != token.ipAddress) {
|
||||
_log.warning('WT cannot be accessed from this IP address');
|
||||
throw AngelHttpException.forbidden(
|
||||
throw ProtevusHttpException.forbidden(
|
||||
message: 'JWT cannot be accessed from this IP address.');
|
||||
}
|
||||
}
|
||||
|
@ -338,11 +339,11 @@ class AngelAuth<User> {
|
|||
return {'data': data, 'token': token.serialize(_hs256)};
|
||||
}
|
||||
} catch (e) {
|
||||
if (e is AngelHttpException) {
|
||||
if (e is ProtevusHttpException) {
|
||||
rethrow;
|
||||
}
|
||||
_log.warning('Malformed JWT');
|
||||
throw AngelHttpException.badRequest(message: 'Malformed JWT');
|
||||
throw ProtevusHttpException.badRequest(message: 'Malformed JWT');
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -354,9 +355,9 @@ class AngelAuth<User> {
|
|||
/// or a `401 Not Authenticated` is thrown, if it is the last one.
|
||||
///
|
||||
/// Any other result is considered an authenticated user, and terminates the loop.
|
||||
RequestHandler authenticate(type, [AngelAuthOptions<User>? opt]) {
|
||||
RequestHandler authenticate(type, [ProtevusAuthOptions<User>? opt]) {
|
||||
return (RequestContext req, ResponseContext res) async {
|
||||
var authOption = opt ?? AngelAuthOptions<User>();
|
||||
var authOption = opt ?? ProtevusAuthOptions<User>();
|
||||
|
||||
var names = <String>[];
|
||||
|
||||
|
@ -451,7 +452,7 @@ class AngelAuth<User> {
|
|||
return false;
|
||||
} else {
|
||||
_log.warning('Not authenticated');
|
||||
throw AngelHttpException.notAuthenticated();
|
||||
throw ProtevusHttpException.notAuthenticated();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -484,7 +485,7 @@ class AngelAuth<User> {
|
|||
}
|
||||
|
||||
/// Log an authenticated user out.
|
||||
RequestHandler logout([AngelAuthOptions<User>? options]) {
|
||||
RequestHandler logout([ProtevusAuthOptions<User>? options]) {
|
||||
return (RequestContext req, ResponseContext res) async {
|
||||
if (req.container?.has<User>() == true) {
|
||||
var user = req.container?.make<User>();
|
||||
|
|
|
@ -1,10 +1,10 @@
|
|||
import 'dart:convert';
|
||||
import 'package:angel3_framework/angel3_framework.dart';
|
||||
import 'package:protevus_framework/protevus_framework.dart';
|
||||
import 'package:http_parser/http_parser.dart';
|
||||
import 'options.dart';
|
||||
|
||||
/// Displays a default callback page to confirm authentication via popups.
|
||||
AngelAuthCallback confirmPopupAuthentication({String eventName = 'token'}) {
|
||||
ProtevusAuthCallback confirmPopupAuthentication({String eventName = 'token'}) {
|
||||
return (req, ResponseContext res, String jwt) {
|
||||
var evt = json.encode(eventName);
|
||||
var detail = json.encode({'detail': jwt});
|
||||
|
|
|
@ -1,12 +1,10 @@
|
|||
import 'dart:async';
|
||||
import 'dart:convert';
|
||||
import 'package:logging/logging.dart';
|
||||
import 'package:angel3_framework/angel3_framework.dart';
|
||||
import 'package:protevus_framework/protevus_framework.dart';
|
||||
import '../options.dart';
|
||||
import '../strategy.dart';
|
||||
|
||||
bool _validateString(String? str) => str != null && str.isNotEmpty;
|
||||
|
||||
/// Determines the validity of an incoming username and password.
|
||||
// typedef FutureOr<User> LocalAuthVerifier<User>(String? username, String? password);
|
||||
typedef LocalAuthVerifier<User> = FutureOr<User?> Function(
|
||||
|
@ -30,7 +28,7 @@ class LocalAuthStrategy<User> extends AuthStrategy<User> {
|
|||
{this.usernameField = 'username',
|
||||
this.passwordField = 'password',
|
||||
this.invalidMessage = 'Please provide a valid username and password.',
|
||||
this.allowBasic = true,
|
||||
this.allowBasic = false,
|
||||
this.forceBasic = false,
|
||||
this.realm = 'Authentication is required.'}) {
|
||||
_log.info('Using LocalAuthStrategy');
|
||||
|
@ -38,8 +36,8 @@ class LocalAuthStrategy<User> extends AuthStrategy<User> {
|
|||
|
||||
@override
|
||||
Future<User?> authenticate(RequestContext req, ResponseContext res,
|
||||
[AngelAuthOptions? options]) async {
|
||||
var _options = options ?? AngelAuthOptions();
|
||||
[ProtevusAuthOptions? options]) async {
|
||||
var localOptions = options ?? ProtevusAuthOptions();
|
||||
User? verificationResult;
|
||||
|
||||
if (allowBasic) {
|
||||
|
@ -57,7 +55,7 @@ class LocalAuthStrategy<User> extends AuthStrategy<User> {
|
|||
await verifier(usrPassMatch.group(1), usrPassMatch.group(2));
|
||||
} else {
|
||||
_log.warning('Bad request: $invalidMessage');
|
||||
throw AngelHttpException.badRequest(errors: [invalidMessage]);
|
||||
throw ProtevusHttpException.badRequest(errors: [invalidMessage]);
|
||||
}
|
||||
|
||||
if (verificationResult == null) {
|
||||
|
@ -68,29 +66,55 @@ class LocalAuthStrategy<User> extends AuthStrategy<User> {
|
|||
return null;
|
||||
}
|
||||
|
||||
return verificationResult;
|
||||
//Allow non-null to pass through
|
||||
//return verificationResult;
|
||||
}
|
||||
}
|
||||
|
||||
if (verificationResult == null) {
|
||||
} else {
|
||||
var body = await req
|
||||
.parseBody()
|
||||
.then((_) => req.bodyAsMap)
|
||||
.catchError((_) => <String, dynamic>{});
|
||||
//if (body != null) {
|
||||
if (_validateString(body[usernameField].toString()) &&
|
||||
_validateString(body[passwordField].toString())) {
|
||||
if (_validateString(body[usernameField]?.toString()) &&
|
||||
_validateString(body[passwordField]?.toString())) {
|
||||
verificationResult = await verifier(
|
||||
body[usernameField].toString(), body[passwordField].toString());
|
||||
body[usernameField]?.toString(), body[passwordField]?.toString());
|
||||
}
|
||||
//}
|
||||
}
|
||||
|
||||
if (verificationResult == null ||
|
||||
(verificationResult is Map && verificationResult.isEmpty)) {
|
||||
if (_options.failureRedirect != null &&
|
||||
_options.failureRedirect!.isNotEmpty) {
|
||||
await res.redirect(_options.failureRedirect, code: 401);
|
||||
// User authentication succeeded can return Map(one element), User(non null) or true
|
||||
if (verificationResult != null && verificationResult != false) {
|
||||
if (verificationResult is Map && verificationResult.isNotEmpty) {
|
||||
return verificationResult;
|
||||
} else if (verificationResult is! Map) {
|
||||
return verificationResult;
|
||||
}
|
||||
}
|
||||
|
||||
// Force basic if set
|
||||
if (forceBasic) {
|
||||
//res.headers['www-authenticate'] = 'Basic realm="$realm"';
|
||||
res
|
||||
..statusCode = 401
|
||||
..headers['www-authenticate'] = 'Basic realm="$realm"';
|
||||
await res.close();
|
||||
return null;
|
||||
}
|
||||
|
||||
// Redirect failed authentication
|
||||
if (localOptions.failureRedirect != null &&
|
||||
localOptions.failureRedirect!.isNotEmpty) {
|
||||
await res.redirect(localOptions.failureRedirect, code: 401);
|
||||
return null;
|
||||
}
|
||||
|
||||
_log.info('Not authenticated');
|
||||
throw ProtevusHttpException.notAuthenticated();
|
||||
|
||||
/*
|
||||
if (verificationResult is Map && verificationResult.isEmpty) {
|
||||
if (localOptions.failureRedirect != null &&
|
||||
localOptions.failureRedirect!.isNotEmpty) {
|
||||
await res.redirect(localOptions.failureRedirect, code: 401);
|
||||
return null;
|
||||
}
|
||||
|
||||
|
@ -105,7 +129,10 @@ class LocalAuthStrategy<User> extends AuthStrategy<User> {
|
|||
return verificationResult;
|
||||
} else {
|
||||
_log.info('Not authenticated');
|
||||
throw AngelHttpException.notAuthenticated();
|
||||
throw ProtevusHttpException.notAuthenticated();
|
||||
}
|
||||
*/
|
||||
}
|
||||
|
||||
bool _validateString(String? str) => str != null && str.isNotEmpty;
|
||||
}
|
||||
|
|
|
@ -1,10 +1,10 @@
|
|||
import 'dart:async';
|
||||
import 'package:angel3_framework/angel3_framework.dart';
|
||||
import 'package:protevus_framework/protevus_framework.dart';
|
||||
import 'options.dart';
|
||||
|
||||
/// A function that handles login and signup for an Angel application.
|
||||
/// A function that handles login and signup for an Protevus application.
|
||||
abstract class AuthStrategy<User> {
|
||||
/// Authenticates or rejects an incoming user.
|
||||
FutureOr<User?> authenticate(RequestContext req, ResponseContext res,
|
||||
[AngelAuthOptions<User>? options]);
|
||||
[ProtevusAuthOptions<User>? options]);
|
||||
}
|
||||
|
|
|
@ -1,22 +1,35 @@
|
|||
name: angel3_auth
|
||||
description: A complete authentication plugin for Angel3. Includes support for stateless JWT tokens, Basic Auth, and more.
|
||||
version: 4.1.2
|
||||
homepage: https://angel3-framework.web.app/
|
||||
repository: https://github.com/dukefirehawk/angel/tree/master/packages/auth
|
||||
name: protevus_auth
|
||||
description: A complete authentication plugin for Protevus. Includes support for stateless JWT tokens, Basic Auth, and more.
|
||||
version: 8.2.0
|
||||
homepage: https://protevus-framework.web.app/
|
||||
repository: https://github.com/dart-backend/protevus/tree/master/packages/auth
|
||||
environment:
|
||||
sdk: '>=2.12.0 <3.0.0'
|
||||
sdk: '>=3.3.0 <4.0.0'
|
||||
dependencies:
|
||||
angel3_framework: ^4.2.0
|
||||
charcode: ^1.2.0
|
||||
collection: ^1.15.0
|
||||
protevus_framework: ^8.0.0
|
||||
charcode: ^1.3.0
|
||||
collection: ^1.17.0
|
||||
crypto: ^3.0.0
|
||||
http_parser: ^4.0.0
|
||||
meta: ^1.3.0
|
||||
quiver: ^3.0.0
|
||||
logging: ^1.0.0
|
||||
meta: ^1.9.0
|
||||
quiver: ^3.2.0
|
||||
logging: ^1.2.0
|
||||
dev_dependencies:
|
||||
angel3_container: ^3.1.0
|
||||
http: ^0.13.1
|
||||
protevus_container: ^8.0.0
|
||||
http: ^1.0.0
|
||||
io: ^1.0.0
|
||||
test: ^1.17.4
|
||||
lints: ^1.0.0
|
||||
test: ^1.24.0
|
||||
lints: ^4.0.0
|
||||
# dependency_overrides:
|
||||
# protevus_container:
|
||||
# path: ../container/angel_container
|
||||
# protevus_framework:
|
||||
# path: ../framework
|
||||
# protevus_http_exception:
|
||||
# path: ../http_exception
|
||||
# protevus_model:
|
||||
# path: ../model
|
||||
# protevus_route:
|
||||
# path: ../route
|
||||
# protevus_mock_request:
|
||||
# path: ../mock_request
|
|
@ -1,4 +1,4 @@
|
|||
import 'package:angel3_auth/src/auth_token.dart';
|
||||
import 'package:protevus_auth/src/auth_token.dart';
|
||||
import 'package:crypto/crypto.dart';
|
||||
import 'package:test/test.dart';
|
||||
|
||||
|
|
|
@ -1,8 +1,8 @@
|
|||
import 'dart:io';
|
||||
import 'package:angel3_auth/angel3_auth.dart';
|
||||
import 'package:angel3_container/mirrors.dart';
|
||||
import 'package:angel3_framework/angel3_framework.dart';
|
||||
import 'package:angel3_framework/http.dart';
|
||||
import 'package:protevus_auth/protevus_auth.dart';
|
||||
import 'package:protevus_container/mirrors.dart';
|
||||
import 'package:protevus_framework/protevus_framework.dart';
|
||||
import 'package:protevus_framework/http.dart';
|
||||
import 'dart:convert';
|
||||
import 'package:collection/collection.dart' show IterableExtension;
|
||||
import 'package:http/http.dart' as http;
|
||||
|
@ -16,7 +16,7 @@ class User extends Model {
|
|||
|
||||
User({this.username, this.password});
|
||||
|
||||
static User parse(Map map) {
|
||||
static User parse(Map<String, dynamic> map) {
|
||||
return User(
|
||||
username: map['username'] as String?,
|
||||
password: map['password'] as String?,
|
||||
|
@ -35,26 +35,27 @@ class User extends Model {
|
|||
}
|
||||
|
||||
void main() {
|
||||
late Angel app;
|
||||
late AngelHttp angelHttp;
|
||||
AngelAuth<User> auth;
|
||||
late Protevus app;
|
||||
late ProtevusHttp angelHttp;
|
||||
ProtevusAuth<User> auth;
|
||||
http.Client? client;
|
||||
HttpServer server;
|
||||
String? url;
|
||||
String? encodedAuth;
|
||||
|
||||
setUp(() async {
|
||||
hierarchicalLoggingEnabled = true;
|
||||
app = Angel(reflector: MirrorsReflector());
|
||||
angelHttp = AngelHttp(app);
|
||||
app = Protevus(reflector: MirrorsReflector());
|
||||
angelHttp = ProtevusHttp(app);
|
||||
app.use('/users', MapService());
|
||||
|
||||
var oldErrorHandler = app.errorHandler;
|
||||
app.errorHandler = (e, req, res) {
|
||||
app.logger?.severe(e.message, e, e.stackTrace ?? StackTrace.current);
|
||||
app.logger.severe(e.message, e, e.stackTrace ?? StackTrace.current);
|
||||
return oldErrorHandler(e, req, res);
|
||||
};
|
||||
|
||||
app.logger = Logger('angel_auth')
|
||||
app.logger = Logger('protevus_auth')
|
||||
..level = Level.FINEST
|
||||
..onRecord.listen((rec) {
|
||||
print(rec);
|
||||
|
@ -72,7 +73,7 @@ void main() {
|
|||
.findService('users')
|
||||
?.create({'username': 'jdoe1', 'password': 'password'});
|
||||
|
||||
auth = AngelAuth<User>(
|
||||
auth = ProtevusAuth<User>(
|
||||
serializer: (u) => u.id ?? '',
|
||||
deserializer: (id) async =>
|
||||
await app.findService('users')?.read(id) as User);
|
||||
|
@ -86,18 +87,18 @@ void main() {
|
|||
var users = await app
|
||||
.findService('users')
|
||||
?.index()
|
||||
.then((it) => it.map<User>((m) => User.parse(m as Map)).toList());
|
||||
.then((it) => it.map<User>((m) => User.parse(m)).toList());
|
||||
|
||||
var result = users?.firstWhereOrNull(
|
||||
(user) => user.username == username && user.password == password);
|
||||
|
||||
return Future.value(result);
|
||||
});
|
||||
}, allowBasic: true);
|
||||
|
||||
app.post(
|
||||
'/login',
|
||||
auth.authenticate('local',
|
||||
AngelAuthOptions(callback: (req, res, token) {
|
||||
ProtevusAuthOptions(callback: (req, res, token) {
|
||||
res
|
||||
..write('Hello!')
|
||||
..close();
|
||||
|
@ -116,6 +117,8 @@ void main() {
|
|||
auth.authenticate('local'),
|
||||
);
|
||||
|
||||
encodedAuth = base64.encode(utf8.encode('jdoe1:password'));
|
||||
|
||||
client = http.Client();
|
||||
server = await angelHttp.startServer();
|
||||
url = 'http://${server.address.address}:${server.port}';
|
||||
|
@ -131,7 +134,7 @@ void main() {
|
|||
|
||||
test('login', () async {
|
||||
final response = await client!.post(Uri.parse('$url/login'),
|
||||
body: {'username': 'jdoe1', 'password': 'password'});
|
||||
headers: {'Authorization': 'Basic $encodedAuth'});
|
||||
print('Response: ${response.body}');
|
||||
expect(response.body, equals('Hello!'));
|
||||
},
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
import 'package:angel3_auth/angel3_auth.dart';
|
||||
import 'package:protevus_auth/protevus_auth.dart';
|
||||
import 'package:test/test.dart';
|
||||
|
||||
void main() {
|
||||
|
|
|
@ -1,19 +1,22 @@
|
|||
import 'dart:async';
|
||||
import 'package:angel3_auth/angel3_auth.dart';
|
||||
import 'package:angel3_framework/angel3_framework.dart';
|
||||
import 'package:angel3_framework/http.dart';
|
||||
import 'package:protevus_auth/protevus_auth.dart';
|
||||
import 'package:protevus_container/mirrors.dart';
|
||||
import 'package:protevus_framework/protevus_framework.dart';
|
||||
import 'package:protevus_framework/http.dart';
|
||||
import 'dart:convert';
|
||||
import 'package:http/http.dart' as http;
|
||||
import 'package:logging/logging.dart';
|
||||
import 'package:test/test.dart';
|
||||
|
||||
final AngelAuth<Map<String, String>> auth = AngelAuth<Map<String, String>>(
|
||||
serializer: (user) async => '1337', deserializer: (id) async => sampleUser);
|
||||
var headers = <String, String>{'accept': 'application/json'};
|
||||
var localOpts = AngelAuthOptions<Map<String, String>>(
|
||||
final ProtevusAuth<Map<String, String>> auth =
|
||||
ProtevusAuth<Map<String, String>>(
|
||||
serializer: (user) async => '1337',
|
||||
deserializer: (id) async => sampleUser);
|
||||
//var headers = <String, String>{'accept': 'application/json'};
|
||||
var localOpts = ProtevusAuthOptions<Map<String, String>>(
|
||||
failureRedirect: '/failure', successRedirect: '/success');
|
||||
var localOpts2 =
|
||||
AngelAuthOptions<Map<String, String>>(canRespondWithJson: false);
|
||||
ProtevusAuthOptions<Map<String, String>>(canRespondWithJson: false);
|
||||
|
||||
Map<String, String> sampleUser = {'hello': 'world'};
|
||||
|
||||
|
@ -25,26 +28,27 @@ Future<Map<String, String>> verifier(String? username, String? password) async {
|
|||
}
|
||||
}
|
||||
|
||||
Future wireAuth(Angel app) async {
|
||||
Future wireAuth(Protevus app) async {
|
||||
//auth.serializer = (user) async => 1337;
|
||||
//auth.deserializer = (id) async => sampleUser;
|
||||
|
||||
auth.strategies['local'] = LocalAuthStrategy(verifier);
|
||||
auth.strategies['local'] = LocalAuthStrategy(verifier, allowBasic: true);
|
||||
await app.configure(auth.configureServer);
|
||||
}
|
||||
|
||||
void main() async {
|
||||
Angel app;
|
||||
late AngelHttp angelHttp;
|
||||
Protevus app;
|
||||
late ProtevusHttp angelHttp;
|
||||
late http.Client client;
|
||||
String? url;
|
||||
String? basicAuthUrl;
|
||||
|
||||
setUp(() async {
|
||||
client = http.Client();
|
||||
app = Angel();
|
||||
angelHttp = AngelHttp(app, useZone: false);
|
||||
app = Protevus(reflector: MirrorsReflector());
|
||||
angelHttp = ProtevusHttp(app, useZone: false);
|
||||
await app.configure(wireAuth);
|
||||
|
||||
app.get('/hello', (req, res) {
|
||||
// => 'Woo auth'
|
||||
return 'Woo auth';
|
||||
|
@ -88,19 +92,21 @@ void main() async {
|
|||
});
|
||||
|
||||
test('successRedirect', () async {
|
||||
var postData = {'username': 'username', 'password': 'password'};
|
||||
//var postData = {'username': 'username', 'password': 'password'};
|
||||
var encodedAuth = base64.encode(utf8.encode('username:password'));
|
||||
|
||||
var response = await client.post(Uri.parse('$url/login'),
|
||||
body: json.encode(postData),
|
||||
headers: {'content-type': 'application/json'});
|
||||
headers: {'Authorization': 'Basic $encodedAuth'});
|
||||
expect(response.statusCode, equals(302));
|
||||
expect(response.headers['location'], equals('/success'));
|
||||
});
|
||||
|
||||
test('failureRedirect', () async {
|
||||
var postData = {'username': 'password', 'password': 'username'};
|
||||
//var postData = {'username': 'password', 'password': 'username'};
|
||||
var encodedAuth = base64.encode(utf8.encode('password:username'));
|
||||
|
||||
var response = await client.post(Uri.parse('$url/login'),
|
||||
body: json.encode(postData),
|
||||
headers: {'content-type': 'application/json'});
|
||||
headers: {'Authorization': 'Basic $encodedAuth'});
|
||||
print('Status Code: ${response.statusCode}');
|
||||
print(response.headers);
|
||||
print(response.body);
|
||||
|
|
|
@ -1,17 +1,17 @@
|
|||
import 'dart:io';
|
||||
|
||||
import 'package:angel3_auth/angel3_auth.dart';
|
||||
import 'package:protevus_auth/protevus_auth.dart';
|
||||
import 'package:test/test.dart';
|
||||
|
||||
const Duration threeDays = Duration(days: 3);
|
||||
|
||||
void main() {
|
||||
late Cookie defaultCookie;
|
||||
var auth = AngelAuth(
|
||||
var auth = ProtevusAuth(
|
||||
secureCookies: true,
|
||||
cookieDomain: 'SECURE',
|
||||
jwtLifeSpan: threeDays.inMilliseconds,
|
||||
serializer: (u) => u as String,
|
||||
serializer: (u) => u,
|
||||
deserializer: (u) => u);
|
||||
|
||||
setUp(() => defaultCookie = Cookie('a', 'b'));
|
||||
|
|
|
@ -1,5 +1,40 @@
|
|||
# Change Log
|
||||
|
||||
## 8.2.0
|
||||
|
||||
* Require Dart >= 3.3
|
||||
* Updated `lints` to 4.0.0
|
||||
|
||||
## 8.1.1
|
||||
|
||||
* Updated repository link
|
||||
|
||||
## 8.1.0
|
||||
|
||||
* Updated `lints` to 3.0.0
|
||||
* Fixed linter warnings
|
||||
|
||||
## 8.0.0
|
||||
|
||||
* Require Dart >= 3.0
|
||||
* Issue: `oauth2` does not support `http` 1.0.0
|
||||
|
||||
## 7.0.1
|
||||
|
||||
* Updated example
|
||||
|
||||
## 7.0.0
|
||||
|
||||
* Require Dart >= 2.17
|
||||
|
||||
## 6.0.0
|
||||
|
||||
* Require Dart >= 2.16
|
||||
|
||||
## 5.0.0
|
||||
|
||||
* Skipped release
|
||||
|
||||
## 4.1.0
|
||||
|
||||
* Updated linter to `package:lints`
|
||||
|
@ -14,15 +49,15 @@
|
|||
|
||||
## 4.0.0
|
||||
|
||||
* Migrated to support Dart SDK 2.12.x NNBD
|
||||
* Migrated to support Dart >= 2.12 NNBD
|
||||
|
||||
## 3.0.0
|
||||
|
||||
* Migrated to work with Dart SDK 2.12.x Non NNBD
|
||||
* Migrated to work with Dart >= 2.12.x Non NNBD
|
||||
|
||||
## 2.1.0
|
||||
|
||||
* Angel 2 + Dart 2 update
|
||||
* Protevus 2 + Dart 2 update
|
||||
* Support for handling errors + rejections.
|
||||
* Use `ExternalAuthOptions`.
|
||||
|
||||
|
@ -32,8 +67,8 @@
|
|||
|
||||
## 2.0.0
|
||||
|
||||
* Angel 2 + Dart 2 updates.
|
||||
* Protevus 2 + Dart 2 updates.
|
||||
|
||||
## 1.0.2
|
||||
|
||||
Added `getParameters` to `AngelOAuth2Options`.
|
||||
Added `getParameters` to `ProtevusOAuth2Options`.
|
||||
|
|
|
@ -1,18 +1,18 @@
|
|||
# Angel3 OAuth2 Handler
|
||||
# Protevus OAuth2 Handler
|
||||
|
||||
![Pub Version (including pre-releases)](https://img.shields.io/pub/v/angel3_auth_oauth2?include_prereleases)
|
||||
![Pub Version (including pre-releases)](https://img.shields.io/pub/v/protevus_auth_oauth2?include_prereleases)
|
||||
![Null Safety](https://img.shields.io/badge/null-safety-brightgreen)(<https://dart.dev/null-safety>)
|
||||
[![Gitter](https://img.shields.io/gitter/room/angel_dart/discussion)](https://gitter.im/angel_dart/discussion)
|
||||
[![License](https://img.shields.io/github/license/dukefirehawk/angel)](https://github.com/dukefirehawk/angel/tree/master/packages/auth_oauth2/LICENSE)
|
||||
[![Discord](https://img.shields.io/discord/1060322353214660698)](https://discord.gg/3X6bxTUdCM)
|
||||
[![License](https://img.shields.io/github/license/dart-backend/protevus)](https://github.com/dart-backend/protevus/tree/master/packages/auth_oauth2/LICENSE)
|
||||
|
||||
Angel3 library for authenticating users with remote identity providers via OAuth2, i.e. Facebook, Google, Azure AD, etc.
|
||||
Protevus library for authenticating users with remote identity providers via OAuth2, i.e. Facebook, Google, Azure AD, etc.
|
||||
|
||||
## Usage
|
||||
|
||||
First, create an options object:
|
||||
|
||||
```dart
|
||||
configureServer(Angel app) async {
|
||||
configureServer(Protevus app) async {
|
||||
// Load from a Map, i.e. app config:
|
||||
var opts = ExternalAuthOptions.fromMap(app.configuration['auth0'] as Map);
|
||||
|
||||
|
@ -55,7 +55,7 @@ OAuth2Verifier oauth2verifier(Service<User> userService) {
|
|||
Now, initialize an `OAuth2Strategy`, using the options and verifier. You'll also need to provide a name for this instance of the strategy. Consider using the name of the remote authentication provider (ex. `facebook`).
|
||||
|
||||
```dart
|
||||
configureServer(Angel app) {
|
||||
configureServer(Protevus app) {
|
||||
auth.strategies['github'] = OAuth2Strategy(
|
||||
options,
|
||||
authorizationEndpoint,
|
||||
|
@ -71,17 +71,17 @@ configureServer(Angel app) {
|
|||
}
|
||||
```
|
||||
|
||||
Lastly, connect it to an `AngelAuth` instance, and wire it up to an `Angel` server. Set up two routes:
|
||||
Lastly, connect it to an `ProtevusAuth` instance, and wire it up to an `Protevus` server. Set up two routes:
|
||||
|
||||
1. Redirect users to the external provider
|
||||
2. Acts as a callback and handles an access code
|
||||
|
||||
In the case of the callback route, you may want to display an HTML page that closes a popup window. In this case, use `confirmPopupAuthentication`, which is bundled with `package:angel3_auth`, as a `callback` function:
|
||||
In the case of the callback route, you may want to display an HTML page that closes a popup window. In this case, use `confirmPopupAuthentication`, which is bundled with `package:protevus_auth`, as a `callback` function:
|
||||
|
||||
```dart
|
||||
configureServer(Angel app) async {
|
||||
configureServer(Protevus app) async {
|
||||
// ...
|
||||
var auth = AngelAuth<User>();
|
||||
var auth = ProtevusAuth<User>();
|
||||
auth.strategies['github'] = oauth2Strategy;
|
||||
|
||||
// Redirect
|
||||
|
@ -90,7 +90,7 @@ configureServer(Angel app) async {
|
|||
// Callback
|
||||
app.get('/auth/github/callback', auth.authenticate(
|
||||
'github',
|
||||
AngelAuthOptions(callback: confirmPopupAuthentication())
|
||||
ProtevusAuthOptions(callback: confirmPopupAuthentication())
|
||||
));
|
||||
|
||||
// Connect the plug-in!!!
|
||||
|
@ -103,7 +103,7 @@ configureServer(Angel app) async {
|
|||
This package should work out-of-the-box for most OAuth2 providers, such as Github or Dropbox. However, if your OAuth2 scopes are separated by a delimiter other than the default (`' '`), you can add it in the `OAuth2Strategy` constructor:
|
||||
|
||||
```dart
|
||||
configureServer(Angel app) async {
|
||||
configureServer(Protevus app) async {
|
||||
OAuth2Strategy(..., delimiter: ' ');
|
||||
}
|
||||
```
|
||||
|
|
|
@ -1,8 +1,8 @@
|
|||
import 'dart:convert';
|
||||
import 'package:angel3_auth/angel3_auth.dart';
|
||||
import 'package:angel3_framework/angel3_framework.dart';
|
||||
import 'package:angel3_framework/http.dart';
|
||||
import 'package:angel3_auth_oauth2/angel3_auth_oauth2.dart';
|
||||
import 'package:protevus_auth/protevus_auth.dart';
|
||||
import 'package:protevus_framework/protevus_framework.dart';
|
||||
import 'package:protevus_framework/http.dart';
|
||||
import 'package:protevus_auth_oauth2/protevus_auth_oauth2.dart';
|
||||
import 'package:http_parser/http_parser.dart';
|
||||
import 'package:logging/logging.dart';
|
||||
|
||||
|
@ -33,9 +33,9 @@ Map<String, dynamic> parseParamsFromGithub(MediaType contentType, String body) {
|
|||
|
||||
void main() async {
|
||||
// Create the server instance.
|
||||
var app = Angel();
|
||||
var http = AngelHttp(app);
|
||||
app.logger = Logger('angel')
|
||||
var app = Protevus();
|
||||
var http = ProtevusHttp(app);
|
||||
app.logger = Logger('protevus')
|
||||
..onRecord.listen((rec) {
|
||||
print(rec);
|
||||
if (rec.error != null) print(rec.error);
|
||||
|
@ -47,7 +47,7 @@ void main() async {
|
|||
var mappedUserService = userService.map(User.parse, User.serialize);
|
||||
|
||||
// Set up the authenticator plugin.
|
||||
var auth = AngelAuth<User>(
|
||||
var auth = ProtevusAuth<User>(
|
||||
serializer: (user) async => user.id ?? '',
|
||||
deserializer: (id) => mappedUserService.read(id),
|
||||
jwtKey: 'oauth2 example secret',
|
||||
|
@ -94,12 +94,12 @@ void main() async {
|
|||
app.get(
|
||||
'/auth/github/callback',
|
||||
auth.authenticate('github',
|
||||
AngelAuthOptions(callback: (req, res, jwt) async {
|
||||
ProtevusAuthOptions(callback: (req, res, jwt) async {
|
||||
// In real-life, you might include a pop-up callback script.
|
||||
//
|
||||
// Use `confirmPopupAuthentication`, which is bundled with
|
||||
// `package:angel_auth`.
|
||||
var user = req.container!.make<User>()!;
|
||||
var user = req.container!.make<User>();
|
||||
res.write('Your user info: ${user.toJson()}\n\n');
|
||||
res.write('Your JWT: $jwt');
|
||||
await res.close();
|
||||
|
@ -113,12 +113,9 @@ void main() async {
|
|||
}
|
||||
|
||||
class User extends Model {
|
||||
@override
|
||||
String? id;
|
||||
|
||||
int? githubId;
|
||||
|
||||
User({this.id, this.githubId});
|
||||
User({super.id, this.githubId});
|
||||
|
||||
static User parse(Map<String, dynamic> map) =>
|
||||
User(id: map['id'] as String?, githubId: map['github_id'] as int?);
|
||||
|
|
|
@ -1,12 +1,12 @@
|
|||
library angel3_auth_oauth2;
|
||||
library protevus_auth_oauth2;
|
||||
|
||||
import 'dart:async';
|
||||
import 'package:angel3_auth/angel3_auth.dart';
|
||||
import 'package:angel3_framework/angel3_framework.dart';
|
||||
import 'package:protevus_auth/protevus_auth.dart';
|
||||
import 'package:protevus_framework/protevus_framework.dart';
|
||||
import 'package:http_parser/http_parser.dart';
|
||||
import 'package:oauth2/oauth2.dart' as oauth2;
|
||||
|
||||
/// An Angel [AuthStrategy] that signs users in via a third-party service that speaks OAuth 2.0.
|
||||
/// An Protevus [AuthStrategy] that signs users in via a third-party service that speaks OAuth 2.0.
|
||||
class OAuth2Strategy<User> implements AuthStrategy<User> {
|
||||
/// A callback that uses the third-party service to authenticate a [User].
|
||||
///
|
||||
|
@ -47,7 +47,7 @@ class OAuth2Strategy<User> implements AuthStrategy<User> {
|
|||
|
||||
@override
|
||||
FutureOr<User?> authenticate(RequestContext req, ResponseContext res,
|
||||
[AngelAuthOptions<User>? options]) async {
|
||||
[ProtevusAuthOptions<User>? options]) async {
|
||||
if (options != null) {
|
||||
var result = await authenticateCallback(req, res, options);
|
||||
if (result is User) {
|
||||
|
@ -71,7 +71,7 @@ class OAuth2Strategy<User> implements AuthStrategy<User> {
|
|||
|
||||
/// The endpoint that is invoked by the third-party after successful authentication.
|
||||
Future<dynamic> authenticateCallback(RequestContext req, ResponseContext res,
|
||||
[AngelAuthOptions? options]) async {
|
||||
[ProtevusAuthOptions? options]) async {
|
||||
var grant = _createGrant();
|
||||
grant.getAuthorizationUrl(this.options.redirectUri,
|
||||
scopes: this.options.scopes);
|
|
@ -1,15 +1,30 @@
|
|||
name: angel3_auth_oauth2
|
||||
version: 4.1.0
|
||||
description: Angel3 library for authenticating users with external identity providers via OAuth2.
|
||||
homepage: https://angel3-framework.web.app/
|
||||
repository: https://github.com/dukefirehawk/angel/tree/master/packages/auth_oauth2
|
||||
name: protevus_auth_oauth2
|
||||
version: 8.2.0
|
||||
description: Protevus library for authenticating users with external identity providers via OAuth2.
|
||||
homepage: https://protevus-framework.web.app/
|
||||
repository: https://github.com/dart-backend/protevus/tree/master/packages/auth_oauth2
|
||||
environment:
|
||||
sdk: '>=2.12.0 <3.0.0'
|
||||
sdk: '>=3.3.0 <4.0.0'
|
||||
dependencies:
|
||||
angel3_auth: ^4.1.0
|
||||
angel3_framework: ^4.2.0
|
||||
protevus_auth: ^8.0.0
|
||||
protevus_framework: ^8.0.0
|
||||
http_parser: ^4.0.0
|
||||
oauth2: ^2.0.0
|
||||
dev_dependencies:
|
||||
logging: ^1.0.1
|
||||
lints: ^1.0.0
|
||||
logging: ^1.2.0
|
||||
lints: ^4.0.0
|
||||
# dependency_overrides:
|
||||
# protevus_container:
|
||||
# path: ../container/angel_container
|
||||
# protevus_framework:
|
||||
# path: ../framework
|
||||
# protevus_http_exception:
|
||||
# path: ../http_exception
|
||||
# protevus_model:
|
||||
# path: ../model
|
||||
# protevus_route:
|
||||
# path: ../route
|
||||
# protevus_mock_request:
|
||||
# path: ../mock_request
|
||||
# protevus_auth:
|
||||
# path: ../auth
|
||||
|
|
|
@ -1,16 +1,36 @@
|
|||
# Change Log
|
||||
|
||||
## 8.0.0
|
||||
|
||||
* Require Dart >= 3.3
|
||||
* Updated `oauth1` to `belatuk_oauth1`
|
||||
* Updated `lints` to 4.0.0
|
||||
* Updated repository link
|
||||
* Fixed linter warnings
|
||||
|
||||
## 7.0.0
|
||||
|
||||
* Require Dart >= 2.17
|
||||
|
||||
## 6.0.0
|
||||
|
||||
* Require Dart >= 2.16
|
||||
|
||||
## 5.0.0
|
||||
|
||||
* Skipped release
|
||||
|
||||
## 4.0.0
|
||||
|
||||
* Migrated to support Dart SDK 2.12.x NNBD
|
||||
* Migrated to support Dart >= 2.12 NNBD
|
||||
|
||||
## 3.0.0
|
||||
|
||||
* Migrated to work with Dart SDK 2.12.x Non NNBD
|
||||
* Migrated to work with Dart >= 2.12 Non NNBD
|
||||
|
||||
## 2.0.0
|
||||
|
||||
* Angel 2 + Dart 2 suppport.
|
||||
* Protevus 2 + Dart 2 suppport.
|
||||
* Use `package:twitter` instead of `package:twit`.
|
||||
* Add `TwitterAuthorizationException`.
|
||||
* Add `onError` callback.
|
||||
|
|
|
@ -1,21 +1,29 @@
|
|||
MIT License (MIT)
|
||||
BSD 3-Clause License
|
||||
|
||||
Copyright (c) 2021 dukefirehawk.com
|
||||
Copyright (c) 2023, dukefirehawk.com
|
||||
All rights reserved.
|
||||
|
||||
Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
of this software and associated documentation files (the "Software"), to deal
|
||||
in the Software without restriction, including without limitation the rights
|
||||
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
copies of the Software, and to permit persons to whom the Software is
|
||||
furnished to do so, subject to the following conditions:
|
||||
Redistribution and use in source and binary forms, with or without
|
||||
modification, are permitted provided that the following conditions are met:
|
||||
|
||||
The above copyright notice and this permission notice shall be included in all
|
||||
copies or substantial portions of the Software.
|
||||
1. Redistributions of source code must retain the above copyright notice, this
|
||||
list of conditions and the following disclaimer.
|
||||
|
||||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||
SOFTWARE.
|
||||
2. Redistributions in binary form must reproduce the above copyright notice,
|
||||
this list of conditions and the following disclaimer in the documentation
|
||||
and/or other materials provided with the distribution.
|
||||
|
||||
3. Neither the name of the copyright holder nor the names of its
|
||||
contributors may be used to endorse or promote products derived from
|
||||
this software without specific prior written permission.
|
||||
|
||||
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
|
||||
AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
||||
IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
|
||||
DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
|
||||
FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
|
||||
DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
|
||||
SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
|
||||
CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
|
||||
OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
|
||||
OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
|
|
|
@ -1,10 +1,11 @@
|
|||
# Angel3 Auth Twitter
|
||||
# Protevus Twitter OAuth1
|
||||
|
||||
![Pub Version (including pre-releases)](https://img.shields.io/pub/v/angel3_auth_twitter?include_prereleases)
|
||||
![Pub Version (including pre-releases)](https://img.shields.io/pub/v/protevus_auth_twitter?include_prereleases)
|
||||
![Null Safety](https://img.shields.io/badge/null-safety-brightgreen)](<https://dart.dev/null-safety>)
|
||||
[![Gitter](https://img.shields.io/gitter/room/angel_dart/discussion)](https://gitter.im/angel_dart/discussion)
|
||||
[![License](https://img.shields.io/github/license/dukefirehawk/angel)](https://github.com/dukefirehawk/angel/tree/master/packages/auth_twitter/LICENSE)
|
||||
[![Discord](https://img.shields.io/discord/1060322353214660698)](https://discord.gg/3X6bxTUdCM)
|
||||
[![License](https://img.shields.io/github/license/dart-backend/protevus)](https://github.com/dart-backend/protevus/tree/master/packages/auth_twitter/LICENSE)
|
||||
|
||||
Angel3 authentication strategy for Twitter login.
|
||||
**Not ready for release**
|
||||
Protevus authentication strategy using Twitter OAuth 1.0a.
|
||||
|
||||
See the [example](example/server.dart);
|
||||
See the [example](example/example.dart);
|
||||
|
|
|
@ -1,9 +1,9 @@
|
|||
import 'dart:convert';
|
||||
import 'dart:io';
|
||||
import 'package:angel_auth/angel_auth.dart';
|
||||
import 'package:angel_auth_twitter/angel_auth_twitter.dart';
|
||||
import 'package:angel_framework/angel_framework.dart';
|
||||
import 'package:angel_framework/http.dart';
|
||||
import 'package:protevus_auth/protevus_auth.dart';
|
||||
import 'package:protevus_auth_twitter/protevus_auth_twitter.dart';
|
||||
import 'package:protevus_framework/protevus_framework.dart';
|
||||
import 'package:protevus_framework/http.dart';
|
||||
import 'package:logging/logging.dart';
|
||||
|
||||
class _User {
|
||||
|
@ -15,9 +15,9 @@ class _User {
|
|||
}
|
||||
|
||||
void main() async {
|
||||
var app = Angel();
|
||||
var http = AngelHttp(app);
|
||||
var auth = AngelAuth<_User>(
|
||||
var app = Protevus();
|
||||
var http = ProtevusHttp(app);
|
||||
var auth = ProtevusAuth<_User>(
|
||||
jwtKey: 'AUTH_TWITTER_SECRET',
|
||||
allowCookie: false,
|
||||
serializer: (user) async => user.handle,
|
||||
|
@ -38,7 +38,7 @@ void main() async {
|
|||
'http://localhost:3000/auth/twitter/callback',
|
||||
),
|
||||
(twit, req, res) async {
|
||||
var response = await twit.twitterClient.get(Uri.parse(
|
||||
var response = await twit.client.get(Uri.parse(
|
||||
'https://api.twitter.com/1.1/account/verify_credentials.json'));
|
||||
var userData = json.decode(response.body) as Map;
|
||||
return _User(userData['screen_name'] as String);
|
||||
|
@ -53,15 +53,13 @@ void main() async {
|
|||
},
|
||||
);
|
||||
|
||||
app
|
||||
..fallback(auth.decodeJwt)
|
||||
..get('/', auth.authenticate('twitter'));
|
||||
app.get('/', auth.authenticate('twitter'));
|
||||
|
||||
app.get(
|
||||
'/auth/twitter/callback',
|
||||
auth.authenticate(
|
||||
'twitter',
|
||||
AngelAuthOptions(
|
||||
ProtevusAuthOptions(
|
||||
callback: (req, res, jwt) {
|
||||
return res.redirect('/home?token=$jwt');
|
||||
},
|
||||
|
@ -74,7 +72,7 @@ void main() async {
|
|||
chain([
|
||||
requireAuthentication<_User>(),
|
||||
(req, res) {
|
||||
var user = req.container.make<_User>();
|
||||
var user = req.container!.make<_User>();
|
||||
res.write('Your Twitter handle is ${user.handle}');
|
||||
return false;
|
||||
},
|
|
@ -1,11 +1,13 @@
|
|||
import 'dart:async';
|
||||
import 'dart:convert';
|
||||
import 'package:angel_auth/angel_auth.dart';
|
||||
import 'package:angel_framework/angel_framework.dart';
|
||||
import 'dart:io';
|
||||
import 'package:protevus_auth/protevus_auth.dart';
|
||||
import 'package:protevus_framework/protevus_framework.dart';
|
||||
import 'package:http/http.dart' as http;
|
||||
import 'package:oauth/oauth.dart' as oauth;
|
||||
import 'package:path/path.dart' as p;
|
||||
import 'package:twitter/twitter.dart';
|
||||
//import 'package:oauth1/oauth1.dart' as oauth;
|
||||
import 'package:belatuk_oauth1/belatuk_oauth1.dart' as oauth;
|
||||
import 'package:dart_twitter_api/twitter_api.dart';
|
||||
|
||||
/// Authenticates users by connecting to Twitter's API.
|
||||
class TwitterStrategy<User> extends AuthStrategy<User> {
|
||||
|
@ -15,7 +17,7 @@ class TwitterStrategy<User> extends AuthStrategy<User> {
|
|||
/// A callback that uses Twitter to authenticate a [User].
|
||||
///
|
||||
/// As always, return `null` if authentication fails.
|
||||
final FutureOr<User> Function(Twitter, RequestContext, ResponseContext)
|
||||
final FutureOr<User> Function(TwitterApi, RequestContext, ResponseContext)
|
||||
verifier;
|
||||
|
||||
/// A callback that is triggered when an OAuth2 error occurs (i.e. the user declines to login);
|
||||
|
@ -25,17 +27,47 @@ class TwitterStrategy<User> extends AuthStrategy<User> {
|
|||
/// The root of Twitter's API. Defaults to `'https://api.twitter.com'`.
|
||||
final Uri baseUrl;
|
||||
|
||||
oauth.Client _client;
|
||||
oauth.Client? _client;
|
||||
|
||||
/// The underlying [oauth.Client] used to query Twitter.
|
||||
oauth.Client get client => _client;
|
||||
oauth.Client get client => _client!;
|
||||
|
||||
TwitterStrategy(this.options, this.verifier, this.onError,
|
||||
{http.BaseClient client, Uri baseUrl})
|
||||
{http.BaseClient? client, Uri? baseUrl})
|
||||
: baseUrl = baseUrl ?? Uri.parse('https://api.twitter.com') {
|
||||
var tokens = oauth.Tokens(
|
||||
consumerId: options.clientId, consumerKey: options.clientSecret);
|
||||
_client = oauth.Client(tokens, client: client);
|
||||
// define platform (server)
|
||||
final oauth.Platform platform = oauth.Platform(
|
||||
'$baseUrl/oauth/request_token', // temporary credentials request
|
||||
'$baseUrl/oauth/authorize', // resource owner authorization
|
||||
'$baseUrl/oauth/access_token', // token credentials request
|
||||
oauth.SignatureMethods.hmacSha1 // signature method
|
||||
);
|
||||
|
||||
// define client credentials (consumer keys)
|
||||
final oauth.ClientCredentials clientCredentials =
|
||||
oauth.ClientCredentials(options.clientId, options.clientSecret);
|
||||
|
||||
// create Authorization object with client credentials and platform definition
|
||||
final oauth.Authorization auth =
|
||||
oauth.Authorization(clientCredentials, platform);
|
||||
|
||||
// request temporary credentials (request tokens)
|
||||
auth.requestTemporaryCredentials('oob').then((res) {
|
||||
// redirect to authorization page
|
||||
print(
|
||||
"Open with your browser: ${auth.getResourceOwnerAuthorizationURI(res.credentials.token)}");
|
||||
|
||||
// get verifier (PIN)
|
||||
stdout.write("PIN: ");
|
||||
String verifier = stdin.readLineSync() ?? '';
|
||||
|
||||
// request token credentials (access tokens)
|
||||
return auth.requestTokenCredentials(res.credentials, verifier);
|
||||
}).then((res) {
|
||||
// create Client object
|
||||
_client = oauth.Client(
|
||||
platform.signatureMethod, clientCredentials, res.credentials);
|
||||
});
|
||||
}
|
||||
|
||||
/// Handle a response from Twitter.
|
||||
|
@ -60,7 +92,7 @@ class TwitterStrategy<User> extends AuthStrategy<User> {
|
|||
|
||||
/// Get an access token.
|
||||
Future<Map<String, String>> getAccessToken(String token, String verifier) {
|
||||
return _client.post(
|
||||
return client.post(
|
||||
baseUrl.replace(path: p.join(baseUrl.path, 'oauth/access_token')),
|
||||
headers: {
|
||||
'accept': 'application/json'
|
||||
|
@ -75,7 +107,7 @@ class TwitterStrategy<User> extends AuthStrategy<User> {
|
|||
|
||||
/// Get a request token.
|
||||
Future<Map<String, String>> getRequestToken() {
|
||||
return _client.post(
|
||||
return client.post(
|
||||
baseUrl.replace(path: p.join(baseUrl.path, 'oauth/request_token')),
|
||||
headers: {
|
||||
'accept': 'application/json'
|
||||
|
@ -86,8 +118,8 @@ class TwitterStrategy<User> extends AuthStrategy<User> {
|
|||
}
|
||||
|
||||
@override
|
||||
Future<User> authenticate(RequestContext req, ResponseContext res,
|
||||
[AngelAuthOptions options]) async {
|
||||
Future<User?> authenticate(RequestContext req, ResponseContext res,
|
||||
[ProtevusAuthOptions? options]) async {
|
||||
try {
|
||||
if (options != null) {
|
||||
var result = await authenticateCallback(req, res, options);
|
||||
|
@ -107,14 +139,14 @@ class TwitterStrategy<User> extends AuthStrategy<User> {
|
|||
}
|
||||
} on TwitterAuthorizationException catch (e) {
|
||||
var result = await onError(e, req, res);
|
||||
await req.app.executeHandler(result, req, res);
|
||||
await req.app?.executeHandler(result, req, res);
|
||||
await res.close();
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
Future authenticateCallback(
|
||||
RequestContext req, ResponseContext res, AngelAuthOptions options) async {
|
||||
Future authenticateCallback(RequestContext req, ResponseContext res,
|
||||
ProtevusAuthOptions options) async {
|
||||
try {
|
||||
if (req.queryParameters.containsKey('denied')) {
|
||||
throw TwitterAuthorizationException(
|
||||
|
@ -124,8 +156,13 @@ class TwitterStrategy<User> extends AuthStrategy<User> {
|
|||
var token = req.queryParameters['oauth_token'] as String;
|
||||
var verifier = req.queryParameters['oauth_verifier'] as String;
|
||||
var loginData = await getAccessToken(token, verifier);
|
||||
var twitter = Twitter(this.options.clientId, this.options.clientSecret,
|
||||
loginData['oauth_token'], loginData['oauth_token_secret']);
|
||||
var twitter = TwitterApi(
|
||||
client: TwitterClient(
|
||||
consumerKey: this.options.clientId,
|
||||
consumerSecret: this.options.clientSecret,
|
||||
token: loginData['oauth_token'] ?? '',
|
||||
secret: loginData['oauth_token_secret'] ?? ''));
|
||||
|
||||
return await this.verifier(twitter, req, res);
|
||||
} on TwitterAuthorizationException catch (e) {
|
||||
return await onError(e, req, res);
|
|
@ -1,19 +1,34 @@
|
|||
name: "angel3_auth_twitter"
|
||||
version: 3.0.0
|
||||
description: "package:angel3_auth strategy for Twitter login. Auto-signs requests."
|
||||
homepage: "https://github.com/angel-dart/auth_twitter.git"
|
||||
name: "protevus_auth_twitter"
|
||||
description: Protevus authentication strategy for Twitter login. Auto-signs requests.
|
||||
version: 8.0.0
|
||||
homepage: https://protevus-framework.web.app/
|
||||
repository: https://github.com/dart-backend/protevus/tree/master/packages/auth_twitter
|
||||
publish_to: none
|
||||
environment:
|
||||
sdk: ">=2.10.0 <3.0.0"
|
||||
sdk: ">=3.3.0 <4.0.0"
|
||||
dependencies:
|
||||
angel_auth:
|
||||
angel_framework:
|
||||
http: ^0.13.0
|
||||
path: ^1.0.0
|
||||
twitter:
|
||||
git:
|
||||
url: https://github.com/dukefirehawk/twitter.dart.git
|
||||
ref: sdk-2.12.x
|
||||
protevus_auth: ^8.0.0
|
||||
protevus_framework: ^8.0.0
|
||||
http: ^1.0.0
|
||||
path: ^1.9.0
|
||||
belatuk_oauth1: ^3.0.0
|
||||
dart_twitter_api: ^0.5.6+1
|
||||
dev_dependencies:
|
||||
logging: ^1.0.0
|
||||
pedantic: ^1.11.0
|
||||
logging: ^1.2.0
|
||||
lints: ^4.0.0
|
||||
dependency_overrides:
|
||||
http: ^1.0.0
|
||||
# protevus_container:
|
||||
# path: ../container/angel_container
|
||||
# protevus_framework:
|
||||
# path: ../framework
|
||||
# protevus_http_exception:
|
||||
# path: ../http_exception
|
||||
# protevus_model:
|
||||
# path: ../model
|
||||
# protevus_route:
|
||||
# path: ../route
|
||||
# protevus_mock_request:
|
||||
# path: ../mock_request
|
||||
# protevus_auth:
|
||||
# path: ../auth
|
64
packages/body_parser/.gitignore
vendored
64
packages/body_parser/.gitignore
vendored
|
@ -1,64 +0,0 @@
|
|||
# Created by .ignore support plugin (hsz.mobi)
|
||||
### JetBrains template
|
||||
# Covers JetBrains IDEs: IntelliJ, RubyMine, PhpStorm, AppCode, PyCharm, CLion, Android Studio and Webstorm
|
||||
# Reference: https://intellij-support.jetbrains.com/hc/en-us/articles/206544839
|
||||
|
||||
# User-specific stuff:
|
||||
.idea/**/workspace.xml
|
||||
.idea/**/tasks.xml
|
||||
.idea/dictionaries
|
||||
|
||||
# Sensitive or high-churn files:
|
||||
.idea/**/dataSources/
|
||||
.idea/**/dataSources.ids
|
||||
.idea/**/dataSources.xml
|
||||
.idea/**/dataSources.local.xml
|
||||
.idea/**/sqlDataSources.xml
|
||||
.idea/**/dynamic.xml
|
||||
.idea/**/uiDesigner.xml
|
||||
|
||||
# Gradle:
|
||||
.idea/**/gradle.xml
|
||||
.idea/**/libraries
|
||||
|
||||
# CMake
|
||||
cmake-build-debug/
|
||||
|
||||
# Mongo Explorer plugin:
|
||||
.idea/**/mongoSettings.xml
|
||||
|
||||
## File-based project format:
|
||||
*.iws
|
||||
|
||||
## Plugin-specific files:
|
||||
|
||||
# IntelliJ
|
||||
out/
|
||||
|
||||
# mpeltonen/sbt-idea plugin
|
||||
.idea_modules/
|
||||
|
||||
# JIRA plugin
|
||||
atlassian-ide-plugin.xml
|
||||
|
||||
# Cursive Clojure plugin
|
||||
.idea/replstate.xml
|
||||
|
||||
# Crashlytics plugin (for Android Studio and IntelliJ)
|
||||
com_crashlytics_export_strings.xml
|
||||
crashlytics.properties
|
||||
crashlytics-build.properties
|
||||
fabric.properties
|
||||
### Dart template
|
||||
# See https://www.dartlang.org/tools/private-files.html
|
||||
|
||||
# Files and directories created by pub
|
||||
.packages
|
||||
.pub/
|
||||
build/
|
||||
# If you're building an application, you may want to check-in your pubspec.lock
|
||||
pubspec.lock
|
||||
|
||||
# Directory created by dartdoc
|
||||
# If you don't generate documentation locally you can remove this line.
|
||||
doc/api/
|
|
@ -1,4 +0,0 @@
|
|||
language: dart
|
||||
dart:
|
||||
- dev
|
||||
- stable
|
|
@ -1,30 +0,0 @@
|
|||
# Change Log
|
||||
|
||||
## 2.1.2
|
||||
|
||||
* Final release. Replaced by `belatuk_body_parser` package.
|
||||
|
||||
## 2.1.1
|
||||
|
||||
* Fixed calling deprecated methods in unit test
|
||||
|
||||
## 2.1.0
|
||||
|
||||
* Replaced `http_server` with `belatuk_http_server`
|
||||
|
||||
## 2.0.1
|
||||
|
||||
* Fixed source code formating warning
|
||||
* Updated README
|
||||
|
||||
## 2.0.0
|
||||
|
||||
* Migrated to support Dart SDK 2.12.x NNBD
|
||||
|
||||
## 1.1.1
|
||||
|
||||
* Dart 2 updates; should fix Angel in Travis.
|
||||
|
||||
## 1.1.0
|
||||
|
||||
* Add `parseBodyFromStream`
|
|
@ -1,21 +0,0 @@
|
|||
MIT License (MIT)
|
||||
|
||||
Copyright (c) 2021 dukefirehawk.com
|
||||
|
||||
Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
of this software and associated documentation files (the "Software"), to deal
|
||||
in the Software without restriction, including without limitation the rights
|
||||
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
copies of the Software, and to permit persons to whom the Software is
|
||||
furnished to do so, subject to the following conditions:
|
||||
|
||||
The above copyright notice and this permission notice shall be included in all
|
||||
copies or substantial portions of the Software.
|
||||
|
||||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||
SOFTWARE.
|
|
@ -1,77 +0,0 @@
|
|||
# Angel3 Body Parser
|
||||
|
||||
[![version](https://img.shields.io/badge/pub-v2.1.2-brightgreen)](https://pub.dartlang.org/packages/angel3_body_parser)
|
||||
[![Null Safety](https://img.shields.io/badge/null-safety-brightgreen)](https://dart.dev/null-safety)
|
||||
[![Gitter](https://img.shields.io/gitter/room/angel_dart/discussion)](https://gitter.im/angel_dart/discussion)
|
||||
|
||||
[![License](https://img.shields.io/github/license/dukefirehawk/angel)](https://github.com/dukefirehawk/angel/tree/angel3/packages/body_parser/LICENSE)
|
||||
|
||||
**DEPRECATED: Replaced by [`belatuk_body_parser`](https://pub.dartlang.org/packages/belatuk_body_parser) package**
|
||||
|
||||
Parse request bodies and query strings in Dart, as well multipart/form-data uploads. No external dependencies required.
|
||||
|
||||
This is the request body parser powering the [Angel3 framework](https://github.com/dukefirehawk/angel). If you are looking for a server-side solution with dependency injection, WebSockets, and more, then I highly recommend it as your first choice. Bam!
|
||||
|
||||
## Contents
|
||||
|
||||
- [Angel3 Body Parser](#angel3-body-parser)
|
||||
- [Contents](#contents)
|
||||
- [About](#about)
|
||||
- [Installation](#installation)
|
||||
- [Usage](#usage)
|
||||
- [Custom Body Parsing](#custom-body-parsing)
|
||||
|
||||
### About
|
||||
|
||||
I needed something like Express.js's `body-parser` module, so I made it here. It fully supports JSON requests. x-www-form-urlencoded fully supported, as well as query strings. You can also include arrays in your query, in the same way you would for a PHP application. Full file upload support will also be present by the production 1.0.0 release.
|
||||
|
||||
A benefit of this is that primitive types are automatically deserialized correctly. As in, if you have a `hello=1.5` request, then `body['hello']` will equal `1.5` and not `'1.5'`. A very semantic difference, yes, but it relieves stress in my head.
|
||||
|
||||
### Installation
|
||||
|
||||
To install Body Parser for your Dart project, simply add body_parser to your pub dependencies.
|
||||
|
||||
dependencies:
|
||||
angel3_body_parser: ^2.1.0
|
||||
|
||||
### Usage
|
||||
|
||||
Body Parser exposes a simple class called `BodyParseResult`. You can easily parse the query string and request body for a request by calling `Future<BodyParseResult> parseBody`.
|
||||
|
||||
```dart
|
||||
import 'dart:convert';
|
||||
import 'package:angel3_body_parser/angel3_body_parser.dart';
|
||||
|
||||
main() async {
|
||||
// ...
|
||||
await for (HttpRequest request in server) {
|
||||
request.response.write(JSON.encode(await parseBody(request).body));
|
||||
await request.response.close();
|
||||
}
|
||||
}
|
||||
```
|
||||
|
||||
You can also use `buildMapFromUri(Map, String)` to populate a map from a URL encoded string.
|
||||
|
||||
This can easily be used with a library like [Angel3 JSON God](https://pub.dev/packages/angel3_json_god) to build structured JSON/REST APIs. Add validation and you've got an instant backend.
|
||||
|
||||
```dart
|
||||
MyClass create(HttpRequest request) async {
|
||||
return god.deserialize(await parseBody(request).body, MyClass);
|
||||
}
|
||||
```
|
||||
|
||||
### Custom Body Parsing
|
||||
|
||||
In cases where you need to parse unrecognized content types, `body_parser` won't be of any help to you on its own. However, you can use the `originalBuffer` property of a `BodyParseResult` to see the original request buffer. To get this functionality, pass `storeOriginalBuffer` as `true` when calling `parseBody`.
|
||||
|
||||
For example, if you wanted to [parse GraphQL queries within your server](https://github.com/dukefirehawk/graphql_dart)...
|
||||
|
||||
```dart
|
||||
app.get('/graphql', (req, res) async {
|
||||
if (req.headers.contentType.mimeType == 'application/graphql') {
|
||||
var graphQlString = String.fromCharCodes(req.originalBuffer);
|
||||
// ...
|
||||
}
|
||||
});
|
||||
```
|
|
@ -1,4 +0,0 @@
|
|||
include: package:pedantic/analysis_options.yaml
|
||||
analyzer:
|
||||
strong-mode:
|
||||
implicit-casts: false
|
|
@ -1,61 +0,0 @@
|
|||
import 'dart:async';
|
||||
import 'dart:convert';
|
||||
import 'dart:io';
|
||||
import 'dart:isolate';
|
||||
import 'package:http_parser/http_parser.dart';
|
||||
import 'package:angel3_body_parser/angel3_body_parser.dart';
|
||||
|
||||
void main() async {
|
||||
var address = '127.0.0.1';
|
||||
var port = 3000;
|
||||
var futures = <Future>[];
|
||||
|
||||
for (var i = 1; i < Platform.numberOfProcessors; i++) {
|
||||
futures.add(Isolate.spawn(start, [address, port, i]));
|
||||
}
|
||||
|
||||
await Future.wait(futures).then((_) {
|
||||
print('All instances started.');
|
||||
print(
|
||||
'Test with "wrk -t12 -c400 -d30s -s ./example/post.lua http://localhost:3000" or similar');
|
||||
start([address, port, 0]);
|
||||
});
|
||||
}
|
||||
|
||||
void start(List args) {
|
||||
var address = InternetAddress(args[0] as String);
|
||||
var port = 8080;
|
||||
if (args[1] is int) {
|
||||
args[1];
|
||||
}
|
||||
|
||||
var id = 0;
|
||||
if (args[2] is int) {
|
||||
args[2];
|
||||
}
|
||||
|
||||
HttpServer.bind(address, port, shared: true).then((server) {
|
||||
server.listen((request) async {
|
||||
// ignore: deprecated_member_use
|
||||
var body = await defaultParseBody(request);
|
||||
request.response
|
||||
..headers.contentType = ContentType('application', 'json')
|
||||
..write(json.encode(body.body));
|
||||
await request.response.close();
|
||||
});
|
||||
|
||||
print(
|
||||
'Server #$id listening at http://${server.address.address}:${server.port}');
|
||||
});
|
||||
}
|
||||
|
||||
Future<BodyParseResult> defaultParseBody(HttpRequest request,
|
||||
{bool storeOriginalBuffer = false}) {
|
||||
return parseBodyFromStream(
|
||||
request,
|
||||
request.headers.contentType != null
|
||||
? MediaType.parse(request.headers.contentType.toString())
|
||||
: null,
|
||||
request.uri,
|
||||
storeOriginalBuffer: storeOriginalBuffer);
|
||||
}
|
|
@ -1,6 +0,0 @@
|
|||
-- example HTTP POST script which demonstrates setting the
|
||||
-- HTTP method, body, and adding a header
|
||||
|
||||
wrk.method = "POST"
|
||||
wrk.body = "foo=bar&baz=quux"
|
||||
wrk.headers["Content-Type"] = "application/x-www-form-urlencoded"
|
|
@ -1,6 +0,0 @@
|
|||
/// A library for parsing HTTP request bodies and queries.
|
||||
library angel3_body_parser;
|
||||
|
||||
export 'src/body_parse_result.dart';
|
||||
export 'src/file_upload_info.dart';
|
||||
export 'src/parse_body.dart';
|
|
@ -1,28 +0,0 @@
|
|||
import 'file_upload_info.dart';
|
||||
|
||||
/// A representation of data from an incoming request.
|
||||
abstract class BodyParseResult {
|
||||
/// The parsed body.
|
||||
Map<String?, dynamic> get body;
|
||||
|
||||
/// The parsed query string.
|
||||
Map<String?, dynamic> get query;
|
||||
|
||||
/// All files uploaded within this request.
|
||||
List<FileUploadInfo> get files;
|
||||
|
||||
/// The original body bytes sent with this request.
|
||||
///
|
||||
/// You must set [storeOriginalBuffer] to `true` to see this.
|
||||
List<int>? get originalBuffer;
|
||||
|
||||
/// If an error was encountered while parsing the body, it will appear here.
|
||||
///
|
||||
/// Otherwise, this is `null`.
|
||||
dynamic get error;
|
||||
|
||||
/// If an error was encountered while parsing the body, the call stack will appear here.
|
||||
///
|
||||
/// Otherwise, this is `null`.
|
||||
StackTrace? get stack;
|
||||
}
|
|
@ -1,7 +0,0 @@
|
|||
import 'file_upload_info.dart';
|
||||
|
||||
List<FileUploadInfo> getFileDataFromChunk(
|
||||
String chunk, String boundary, String fileUploadName, Map body) {
|
||||
var result = <FileUploadInfo>[];
|
||||
return result;
|
||||
}
|
|
@ -1,17 +0,0 @@
|
|||
/// Represents a file uploaded to the server.
|
||||
class FileUploadInfo {
|
||||
/// The MIME type of the uploaded file.
|
||||
String? mimeType;
|
||||
|
||||
/// The name of the file field from the request.
|
||||
String? name;
|
||||
|
||||
/// The filename of the file.
|
||||
String? filename;
|
||||
|
||||
/// The bytes that make up this file.
|
||||
List<int> data;
|
||||
|
||||
FileUploadInfo(
|
||||
{this.mimeType, this.name, this.filename, this.data = const []});
|
||||
}
|
|
@ -1,22 +0,0 @@
|
|||
import 'dart:convert';
|
||||
|
||||
dynamic getValue(String value) {
|
||||
try {
|
||||
var numValue = num.parse(value);
|
||||
if (!numValue.isNaN) {
|
||||
return numValue;
|
||||
} else {
|
||||
return value;
|
||||
}
|
||||
} on FormatException {
|
||||
if (value.startsWith('[') && value.endsWith(']')) {
|
||||
return json.decode(value);
|
||||
} else if (value.startsWith('{') && value.endsWith('}')) {
|
||||
return json.decode(value);
|
||||
} else if (value.trim().toLowerCase() == 'null') {
|
||||
return null;
|
||||
} else {
|
||||
return value;
|
||||
}
|
||||
}
|
||||
}
|
|
@ -1,44 +0,0 @@
|
|||
import 'get_value.dart';
|
||||
|
||||
/// Parses a URI-encoded string into real data! **Wow!**
|
||||
///
|
||||
/// Whichever map you provide will be automatically populated from the urlencoded body string you provide.
|
||||
void buildMapFromUri(Map map, String body) {
|
||||
var parseArrayRgx = RegExp(r'^(.+)\[\]$');
|
||||
|
||||
for (var keyValuePair in body.split('&')) {
|
||||
if (keyValuePair.contains('=')) {
|
||||
var equals = keyValuePair.indexOf('=');
|
||||
var key = Uri.decodeQueryComponent(keyValuePair.substring(0, equals));
|
||||
var value = Uri.decodeQueryComponent(keyValuePair.substring(equals + 1));
|
||||
|
||||
if (parseArrayRgx.hasMatch(key)) {
|
||||
Match queryMatch = parseArrayRgx.firstMatch(key)!;
|
||||
key = queryMatch.group(1)!;
|
||||
if (!(map[key] is List)) {
|
||||
map[key] = [];
|
||||
}
|
||||
|
||||
map[key].add(getValue(value));
|
||||
} else if (key.contains('.')) {
|
||||
// i.e. map.foo.bar => [map, foo, bar]
|
||||
var keys = key.split('.');
|
||||
|
||||
var targetMap = map[keys[0]] != null ? map[keys[0]] as Map? : {};
|
||||
map[keys[0]] = targetMap;
|
||||
for (var i = 1; i < keys.length; i++) {
|
||||
if (i < keys.length - 1) {
|
||||
targetMap![keys[i]] = targetMap[keys[i]] ?? {};
|
||||
targetMap = targetMap[keys[i]] as Map?;
|
||||
} else {
|
||||
targetMap![keys[i]] = getValue(value);
|
||||
}
|
||||
}
|
||||
} else {
|
||||
map[key] = getValue(value);
|
||||
}
|
||||
} else {
|
||||
map[Uri.decodeQueryComponent(keyValuePair)] = true;
|
||||
}
|
||||
}
|
||||
}
|
|
@ -1,149 +0,0 @@
|
|||
import 'dart:async';
|
||||
import 'dart:convert';
|
||||
import 'dart:io';
|
||||
import 'dart:typed_data';
|
||||
|
||||
import 'package:http_parser/http_parser.dart';
|
||||
import 'package:belatuk_http_server/belatuk_http_server.dart';
|
||||
import 'package:mime/mime.dart';
|
||||
|
||||
import 'body_parse_result.dart';
|
||||
import 'file_upload_info.dart';
|
||||
import 'map_from_uri.dart';
|
||||
|
||||
/// Forwards to [parseBodyFromStream].
|
||||
@deprecated
|
||||
Future<BodyParseResult> parseBody(HttpRequest request,
|
||||
{bool storeOriginalBuffer = false}) {
|
||||
return parseBodyFromStream(
|
||||
request,
|
||||
request.headers.contentType != null
|
||||
? MediaType.parse(request.headers.contentType.toString())
|
||||
: null,
|
||||
request.uri,
|
||||
storeOriginalBuffer: storeOriginalBuffer);
|
||||
}
|
||||
|
||||
/// Grabs data from an incoming request.
|
||||
///
|
||||
/// Supports URL-encoded and JSON, as well as multipart/* forms.
|
||||
/// On a file upload request, only fields with the name **'file'** are processed
|
||||
/// as files. Anything else is put in the body. You can change the upload file name
|
||||
/// via the *fileUploadName* parameter. :)
|
||||
///
|
||||
/// Use [storeOriginalBuffer] to add the original request bytes to the result.
|
||||
Future<BodyParseResult> parseBodyFromStream(
|
||||
Stream<Uint8List> data, MediaType? contentType, Uri requestUri,
|
||||
{bool storeOriginalBuffer = false}) async {
|
||||
var result = _BodyParseResultImpl();
|
||||
|
||||
Future<Uint8List> getBytes() {
|
||||
return data
|
||||
.fold<BytesBuilder>(BytesBuilder(copy: false), (a, b) => a..add(b))
|
||||
.then((b) => b.takeBytes());
|
||||
}
|
||||
|
||||
Future<String> getBody() {
|
||||
if (storeOriginalBuffer) {
|
||||
return getBytes().then((bytes) {
|
||||
result.originalBuffer = bytes;
|
||||
return utf8.decode(bytes);
|
||||
});
|
||||
} else {
|
||||
return utf8.decoder.bind(data).join();
|
||||
}
|
||||
}
|
||||
|
||||
try {
|
||||
if (contentType != null) {
|
||||
if (contentType.type == 'multipart' &&
|
||||
contentType.parameters.containsKey('boundary')) {
|
||||
Stream<Uint8List> stream;
|
||||
|
||||
if (storeOriginalBuffer) {
|
||||
var bytes = result.originalBuffer = await getBytes();
|
||||
var ctrl = StreamController<Uint8List>()..add(bytes);
|
||||
await ctrl.close();
|
||||
stream = ctrl.stream;
|
||||
} else {
|
||||
stream = data;
|
||||
}
|
||||
|
||||
var parts =
|
||||
MimeMultipartTransformer(contentType.parameters['boundary']!)
|
||||
.bind(stream)
|
||||
.map((part) =>
|
||||
HttpMultipartFormData.parse(part, defaultEncoding: utf8));
|
||||
|
||||
await for (HttpMultipartFormData part in parts) {
|
||||
if (part.isBinary ||
|
||||
part.contentDisposition.parameters.containsKey('filename')) {
|
||||
var builder = await part.fold(
|
||||
BytesBuilder(copy: false),
|
||||
(BytesBuilder b, d) =>
|
||||
b..add(d is! String ? (d as List<int>?)! : d.codeUnits));
|
||||
var upload = FileUploadInfo(
|
||||
mimeType: part.contentType!.mimeType,
|
||||
name: part.contentDisposition.parameters['name'],
|
||||
filename:
|
||||
part.contentDisposition.parameters['filename'] ?? 'file',
|
||||
data: builder.takeBytes());
|
||||
result.files.add(upload);
|
||||
} else if (part.isText) {
|
||||
var text = await part.join();
|
||||
buildMapFromUri(result.body,
|
||||
'${part.contentDisposition.parameters["name"]}=$text');
|
||||
}
|
||||
}
|
||||
} else if (contentType.mimeType == 'application/json') {
|
||||
result.body.addAll(
|
||||
_foldToStringDynamic(json.decode(await getBody()) as Map?)!);
|
||||
} else if (contentType.mimeType == 'application/x-www-form-urlencoded') {
|
||||
var body = await getBody();
|
||||
buildMapFromUri(result.body, body);
|
||||
} else if (storeOriginalBuffer == true) {
|
||||
result.originalBuffer = await getBytes();
|
||||
}
|
||||
} else {
|
||||
if (requestUri.hasQuery) {
|
||||
buildMapFromUri(result.query, requestUri.query);
|
||||
}
|
||||
|
||||
if (storeOriginalBuffer == true) {
|
||||
result.originalBuffer = await getBytes();
|
||||
}
|
||||
}
|
||||
} catch (e, st) {
|
||||
result.error = e;
|
||||
result.stack = st;
|
||||
}
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
class _BodyParseResultImpl implements BodyParseResult {
|
||||
@override
|
||||
Map<String?, dynamic> body = {};
|
||||
|
||||
@override
|
||||
List<FileUploadInfo> files = [];
|
||||
|
||||
@override
|
||||
List<int>? originalBuffer;
|
||||
|
||||
@override
|
||||
Map<String?, dynamic> query = {};
|
||||
|
||||
@override
|
||||
var error;
|
||||
|
||||
@override
|
||||
StackTrace? stack;
|
||||
}
|
||||
|
||||
Map<String, dynamic>? _foldToStringDynamic(Map? map) {
|
||||
return map == null
|
||||
? null
|
||||
: map.keys.fold<Map<String, dynamic>>(
|
||||
<String, dynamic>{}, (out, k) => out..[k.toString()] = map[k]);
|
||||
}
|
|
@ -1,15 +0,0 @@
|
|||
name: angel3_body_parser
|
||||
version: 2.1.2
|
||||
description: Parse request bodies and query strings in Dart. Supports JSON, URL-encoded, and multi-part bodies.
|
||||
homepage: https://angel3-framework.web.app/
|
||||
repository: https://github.com/dukefirehawk/angel/tree/angel3/packages/body_parser
|
||||
environment:
|
||||
sdk: '>=2.12.0 <3.0.0'
|
||||
dependencies:
|
||||
http_parser: ^4.0.0
|
||||
belatuk_http_server: ^2.0.0
|
||||
mime: ^1.0.0
|
||||
dev_dependencies:
|
||||
http: ^0.13.0
|
||||
test: ^1.17.0
|
||||
pedantic: ^1.11.0
|
|
@ -1,156 +0,0 @@
|
|||
import 'dart:io';
|
||||
import 'dart:convert';
|
||||
import 'package:angel3_body_parser/angel3_body_parser.dart';
|
||||
import 'package:http/http.dart' as http;
|
||||
import 'package:http_parser/http_parser.dart';
|
||||
import 'package:test/test.dart';
|
||||
import 'server_test.dart';
|
||||
|
||||
Future<BodyParseResult> _parseBody(HttpRequest request) {
|
||||
return parseBodyFromStream(
|
||||
request,
|
||||
request.headers.contentType != null
|
||||
? MediaType.parse(request.headers.contentType.toString())
|
||||
: null,
|
||||
request.uri,
|
||||
storeOriginalBuffer: false);
|
||||
}
|
||||
|
||||
void main() {
|
||||
HttpServer? server;
|
||||
String? url;
|
||||
http.Client? client;
|
||||
|
||||
setUp(() async {
|
||||
server = await HttpServer.bind('127.0.0.1', 0);
|
||||
server!.listen((HttpRequest request) async {
|
||||
//Server will simply return a JSON representation of the parsed body
|
||||
// ignore: deprecated_member_use
|
||||
request.response.write(jsonEncodeBody(await _parseBody(request)));
|
||||
await request.response.close();
|
||||
});
|
||||
url = 'http://localhost:${server!.port}';
|
||||
print('Test server listening on $url');
|
||||
client = http.Client();
|
||||
});
|
||||
|
||||
tearDown(() async {
|
||||
await server!.close(force: true);
|
||||
client!.close();
|
||||
server = null;
|
||||
url = null;
|
||||
client = null;
|
||||
});
|
||||
|
||||
test('No upload', () async {
|
||||
var boundary = 'myBoundary';
|
||||
var headers = <String, String>{
|
||||
'content-type': 'multipart/form-data; boundary=$boundary'
|
||||
};
|
||||
var postData = '''
|
||||
--$boundary
|
||||
Content-Disposition: form-data; name="hello"
|
||||
|
||||
world
|
||||
--$boundary--
|
||||
'''
|
||||
.replaceAll('\n', '\r\n');
|
||||
|
||||
print(
|
||||
'Form Data: \n${postData.replaceAll("\r", "\\r").replaceAll("\n", "\\n")}');
|
||||
var response =
|
||||
await client!.post(Uri.parse(url!), headers: headers, body: postData);
|
||||
print('Response: ${response.body}');
|
||||
var jsons = json.decode(response.body);
|
||||
var files = jsons['files'].map((map) {
|
||||
return map == null
|
||||
? null
|
||||
: map.keys.fold<Map<String, dynamic>>(
|
||||
<String, dynamic>{}, (out, k) => out..[k.toString()] = map[k]);
|
||||
});
|
||||
expect(files.length, equals(0));
|
||||
expect(jsons['body']['hello'], equals('world'));
|
||||
});
|
||||
|
||||
test('Single upload', () async {
|
||||
var boundary = 'myBoundary';
|
||||
var headers = <String, String>{
|
||||
'content-type': ContentType('multipart', 'form-data',
|
||||
parameters: {'boundary': boundary}).toString()
|
||||
};
|
||||
var postData = '''
|
||||
--$boundary
|
||||
Content-Disposition: form-data; name="hello"
|
||||
|
||||
world
|
||||
--$boundary
|
||||
Content-Disposition: form-data; name="file"; filename="app.dart"
|
||||
Content-Type: application/dart
|
||||
|
||||
Hello world
|
||||
--$boundary--
|
||||
'''
|
||||
.replaceAll('\n', '\r\n');
|
||||
|
||||
print(
|
||||
'Form Data: \n${postData.replaceAll("\r", "\\r").replaceAll("\n", "\\n")}');
|
||||
var response =
|
||||
await client!.post(Uri.parse(url!), headers: headers, body: postData);
|
||||
print('Response: ${response.body}');
|
||||
var jsons = json.decode(response.body);
|
||||
var files = jsons['files'];
|
||||
expect(files.length, equals(1));
|
||||
expect(files[0]['name'], equals('file'));
|
||||
expect(files[0]['mimeType'], equals('application/dart'));
|
||||
expect(files[0]['data'].length, equals(11));
|
||||
expect(files[0]['filename'], equals('app.dart'));
|
||||
expect(jsons['body']['hello'], equals('world'));
|
||||
});
|
||||
|
||||
test('Multiple upload', () async {
|
||||
var boundary = 'myBoundary';
|
||||
var headers = <String, String>{
|
||||
'content-type': 'multipart/form-data; boundary=$boundary'
|
||||
};
|
||||
var postData = '''
|
||||
--$boundary
|
||||
Content-Disposition: form-data; name="json"
|
||||
|
||||
god
|
||||
--$boundary
|
||||
Content-Disposition: form-data; name="num"
|
||||
|
||||
14.50000
|
||||
--$boundary
|
||||
Content-Disposition: form-data; name="file"; filename="app.dart"
|
||||
Content-Type: text/plain
|
||||
|
||||
Hello world
|
||||
--$boundary
|
||||
Content-Disposition: form-data; name="entry-point"; filename="main.js"
|
||||
Content-Type: text/javascript
|
||||
|
||||
function main() {
|
||||
console.log("Hello, world!");
|
||||
}
|
||||
--$boundary--
|
||||
'''
|
||||
.replaceAll('\n', '\r\n');
|
||||
|
||||
print(
|
||||
'Form Data: \n${postData.replaceAll("\r", "\\r").replaceAll("\n", "\\n")}');
|
||||
var response =
|
||||
await client!.post(Uri.parse(url!), headers: headers, body: postData);
|
||||
print('Response: ${response.body}');
|
||||
var jsons = json.decode(response.body);
|
||||
var files = jsons['files'];
|
||||
expect(files.length, equals(2));
|
||||
expect(files[0]['name'], equals('file'));
|
||||
expect(files[0]['mimeType'], equals('text/plain'));
|
||||
expect(files[0]['data'].length, equals(11));
|
||||
expect(files[1]['name'], equals('entry-point'));
|
||||
expect(files[1]['mimeType'], equals('text/javascript'));
|
||||
expect(jsons['body']['json'], equals('god'));
|
||||
expect(jsons['body']['num'], equals(14.5));
|
||||
});
|
||||
}
|
|
@ -1,174 +0,0 @@
|
|||
import 'dart:convert';
|
||||
import 'dart:io' show HttpRequest, HttpServer;
|
||||
|
||||
import 'package:angel3_body_parser/angel3_body_parser.dart';
|
||||
import 'package:http/http.dart' as http;
|
||||
import 'package:http_parser/http_parser.dart';
|
||||
import 'package:test/test.dart';
|
||||
|
||||
const TOKEN =
|
||||
'eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJhdWQiOiIxMjcuMC4wLjEiLCJleHAiOi0xLCJpYXQiOiIyMDE2LTEyLTIyVDEyOjQ5OjUwLjM2MTQ0NiIsImlzcyI6ImFuZ2VsX2F1dGgiLCJzdWIiOiIxMDY2OTQ4Mzk2MDIwMjg5ODM2NTYifQ==.PYw7yUb-cFWD7N0sSLztP7eeRvO44nu1J2OgDNyT060=';
|
||||
|
||||
String jsonEncodeBody(BodyParseResult result) {
|
||||
return json.encode({
|
||||
'query': result.query,
|
||||
'body': result.body,
|
||||
'error': result.error?.toString(),
|
||||
'files': result.files.map((f) {
|
||||
return {
|
||||
'name': f.name,
|
||||
'mimeType': f.mimeType,
|
||||
'filename': f.filename,
|
||||
'data': f.data,
|
||||
};
|
||||
}).toList(),
|
||||
'originalBuffer': result.originalBuffer,
|
||||
'stack': null, //result.stack.toString(),
|
||||
});
|
||||
}
|
||||
|
||||
Future<BodyParseResult> _parseBody(HttpRequest request) {
|
||||
return parseBodyFromStream(
|
||||
request,
|
||||
request.headers.contentType != null
|
||||
? MediaType.parse(request.headers.contentType.toString())
|
||||
: null,
|
||||
request.uri,
|
||||
storeOriginalBuffer: true);
|
||||
}
|
||||
|
||||
void main() {
|
||||
HttpServer? server;
|
||||
String? url;
|
||||
http.Client? client;
|
||||
|
||||
setUp(() async {
|
||||
server = await HttpServer.bind('127.0.0.1', 0);
|
||||
server!.listen((HttpRequest request) async {
|
||||
//Server will simply return a JSON representation of the parsed body
|
||||
request.response.write(
|
||||
// ignore: deprecated_member_use
|
||||
jsonEncodeBody(await _parseBody(request)));
|
||||
await request.response.close();
|
||||
});
|
||||
url = 'http://localhost:${server!.port}';
|
||||
print('Test server listening on $url');
|
||||
client = http.Client();
|
||||
});
|
||||
tearDown(() async {
|
||||
await server!.close(force: true);
|
||||
client!.close();
|
||||
server = null;
|
||||
url = null;
|
||||
client = null;
|
||||
});
|
||||
|
||||
group('query string', () {
|
||||
test('GET Simple', () async {
|
||||
print('GET $url/?hello=world');
|
||||
var response = await client!.get(Uri.parse('$url/?hello=world'));
|
||||
print('Response: ${response.body}');
|
||||
var result = json.decode(response.body);
|
||||
expect(result['body'], equals({}));
|
||||
expect(result['query'], equals({'hello': 'world'}));
|
||||
expect(result['files'], equals([]));
|
||||
//expect(result['originalBuffer'], isNull);
|
||||
});
|
||||
|
||||
test('GET Complex', () async {
|
||||
var postData =
|
||||
'hello=world&nums%5B%5D=1&nums%5B%5D=2.0&nums%5B%5D=${3 - 1}&map.foo.bar=baz';
|
||||
print('Body: $postData');
|
||||
var response = await client!.get(Uri.parse('$url/?$postData'));
|
||||
print('Response: ${response.body}');
|
||||
var query = json.decode(response.body)['query'];
|
||||
expect(query['hello'], equals('world'));
|
||||
expect(query['nums'][2], equals(2));
|
||||
expect(query['map'] is Map, equals(true));
|
||||
expect(query['map']['foo'], equals({'bar': 'baz'}));
|
||||
});
|
||||
|
||||
test('JWT', () async {
|
||||
var postData = 'token=$TOKEN';
|
||||
print('Body: $postData');
|
||||
var response = await client!.get(Uri.parse('$url/?$postData'));
|
||||
print('Response: ${response.body}');
|
||||
var query = json.decode(response.body)['query'];
|
||||
expect(query['token'], equals(TOKEN));
|
||||
});
|
||||
});
|
||||
|
||||
group('urlencoded', () {
|
||||
var headers = <String, String>{
|
||||
'content-type': 'application/x-www-form-urlencoded'
|
||||
};
|
||||
test('POST Simple', () async {
|
||||
print('Body: hello=world');
|
||||
var response = await client!
|
||||
.post(Uri.parse(url!), headers: headers, body: 'hello=world');
|
||||
print('Response: ${response.body}');
|
||||
var result = json.decode(response.body);
|
||||
expect(result['query'], equals({}));
|
||||
expect(result['body'], equals({'hello': 'world'}));
|
||||
expect(result['files'], equals([]));
|
||||
expect(result['originalBuffer'], isList);
|
||||
expect(result['originalBuffer'], isNotEmpty);
|
||||
});
|
||||
|
||||
test('Post Complex', () async {
|
||||
var postData =
|
||||
'hello=world&nums%5B%5D=1&nums%5B%5D=2.0&nums%5B%5D=${3 - 1}&map.foo.bar=baz';
|
||||
var response =
|
||||
await client!.post(Uri.parse(url!), headers: headers, body: postData);
|
||||
print('Response: ${response.body}');
|
||||
var body = json.decode(response.body)['body'];
|
||||
expect(body['hello'], equals('world'));
|
||||
expect(body['nums'][2], equals(2));
|
||||
expect(body['map'] is Map, equals(true));
|
||||
expect(body['map']['foo'], equals({'bar': 'baz'}));
|
||||
});
|
||||
|
||||
test('JWT', () async {
|
||||
var postData = 'token=$TOKEN';
|
||||
var response =
|
||||
await client!.post(Uri.parse(url!), headers: headers, body: postData);
|
||||
var body = json.decode(response.body)['body'];
|
||||
expect(body['token'], equals(TOKEN));
|
||||
});
|
||||
});
|
||||
|
||||
group('json', () {
|
||||
var headers = <String, String>{'content-type': 'application/json'};
|
||||
test('Post Simple', () async {
|
||||
var postData = json.encode({'hello': 'world'});
|
||||
print('Body: $postData');
|
||||
var response =
|
||||
await client!.post(Uri.parse(url!), headers: headers, body: postData);
|
||||
print('Response: ${response.body}');
|
||||
var result = json.decode(response.body);
|
||||
expect(result['body'], equals({'hello': 'world'}));
|
||||
expect(result['query'], equals({}));
|
||||
expect(result['files'], equals([]));
|
||||
expect(result['originalBuffer'], allOf(isList, isNotEmpty));
|
||||
});
|
||||
|
||||
test('Post Complex', () async {
|
||||
var postData = json.encode({
|
||||
'hello': 'world',
|
||||
'nums': [1, 2.0, 3 - 1],
|
||||
'map': {
|
||||
'foo': {'bar': 'baz'}
|
||||
}
|
||||
});
|
||||
print('Body: $postData');
|
||||
var response =
|
||||
await client!.post(Uri.parse(url!), headers: headers, body: postData);
|
||||
print('Response: ${response.body}');
|
||||
var body = json.decode(response.body)['body'];
|
||||
expect(body['hello'], equals('world'));
|
||||
expect(body['nums'][2], equals(2));
|
||||
expect(body['map'] is Map, equals(true));
|
||||
expect(body['map']['foo'], equals({'bar': 'baz'}));
|
||||
});
|
||||
});
|
||||
}
|
4
packages/cache/.travis.yml
vendored
4
packages/cache/.travis.yml
vendored
|
@ -1,4 +0,0 @@
|
|||
language: dart
|
||||
dart:
|
||||
- stable
|
||||
- dev
|
38
packages/cache/CHANGELOG.md
vendored
38
packages/cache/CHANGELOG.md
vendored
|
@ -1,5 +1,39 @@
|
|||
# Change Log
|
||||
|
||||
## 8.2.0
|
||||
|
||||
* Require Dart >= 3.3
|
||||
* Updated `lints` to 4.0.0
|
||||
|
||||
## 8.1.1
|
||||
|
||||
* Updated repository link
|
||||
|
||||
## 8.1.0
|
||||
|
||||
* Updated `lints` to 3.0.0
|
||||
* Fixed linter warnings
|
||||
|
||||
## 8.0.0
|
||||
|
||||
* Require Dart >= 3.0
|
||||
|
||||
## 7.0.0
|
||||
|
||||
* Require Dart >= 2.17
|
||||
|
||||
## 6.0.0
|
||||
|
||||
* Require Dart >= 2.16
|
||||
|
||||
## 5.0.0
|
||||
|
||||
* Skipped release
|
||||
|
||||
## 4.0.3
|
||||
|
||||
* Updated linter to `package:lints`
|
||||
|
||||
## 4.0.2
|
||||
|
||||
* Updated README
|
||||
|
@ -14,11 +48,11 @@
|
|||
|
||||
## 4.0.0
|
||||
|
||||
* Migrated to support Dart SDK 2.12.x NNBD
|
||||
* Migrated to support Dart >= 2.12 NNBD
|
||||
|
||||
## 3.0.0
|
||||
|
||||
* Migrated to work with Dart SDK 2.12.x Non NNBD
|
||||
* Migrated to work with Dart >= 2.12 Non NNBD
|
||||
|
||||
## 2.0.1
|
||||
|
||||
|
|
42
packages/cache/LICENSE
vendored
42
packages/cache/LICENSE
vendored
|
@ -1,21 +1,29 @@
|
|||
MIT License (MIT)
|
||||
BSD 3-Clause License
|
||||
|
||||
Copyright (c) 2021 dukefirehawk.com
|
||||
Copyright (c) 2021, dukefirehawk.com
|
||||
All rights reserved.
|
||||
|
||||
Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
of this software and associated documentation files (the "Software"), to deal
|
||||
in the Software without restriction, including without limitation the rights
|
||||
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
copies of the Software, and to permit persons to whom the Software is
|
||||
furnished to do so, subject to the following conditions:
|
||||
Redistribution and use in source and binary forms, with or without
|
||||
modification, are permitted provided that the following conditions are met:
|
||||
|
||||
The above copyright notice and this permission notice shall be included in all
|
||||
copies or substantial portions of the Software.
|
||||
1. Redistributions of source code must retain the above copyright notice, this
|
||||
list of conditions and the following disclaimer.
|
||||
|
||||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||
SOFTWARE.
|
||||
2. Redistributions in binary form must reproduce the above copyright notice,
|
||||
this list of conditions and the following disclaimer in the documentation
|
||||
and/or other materials provided with the distribution.
|
||||
|
||||
3. Neither the name of the copyright holder nor the names of its
|
||||
contributors may be used to endorse or promote products derived from
|
||||
this software without specific prior written permission.
|
||||
|
||||
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
|
||||
AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
||||
IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
|
||||
DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
|
||||
FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
|
||||
DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
|
||||
SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
|
||||
CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
|
||||
OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
|
||||
OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
|
|
29
packages/cache/README.md
vendored
29
packages/cache/README.md
vendored
|
@ -1,16 +1,15 @@
|
|||
# Angel3 HTTP Cache
|
||||
# Protevus HTTP Cache
|
||||
|
||||
[![version](https://img.shields.io/badge/pub-v4.0.2-brightgreen)](https://pub.dev/packages/angel3_cache)
|
||||
![Pub Version (including pre-releases)](https://img.shields.io/pub/v/protevus_cache?include_prereleases)
|
||||
[![Null Safety](https://img.shields.io/badge/null-safety-brightgreen)](https://dart.dev/null-safety)
|
||||
[![Gitter](https://img.shields.io/gitter/room/angel_dart/discussion)](https://gitter.im/angel_dart/discussion)
|
||||
[![Discord](https://img.shields.io/discord/1060322353214660698)](https://discord.gg/3X6bxTUdCM)
|
||||
[![License](https://img.shields.io/github/license/dart-backend/protevus)](https://github.com/dart-backend/protevus/tree/master/packages/cache/LICENSE)
|
||||
|
||||
[![License](https://img.shields.io/github/license/dukefirehawk/angel)](https://github.com/dukefirehawk/angel/tree/angel3/packages/cache/LICENSE)
|
||||
|
||||
A service that provides HTTP caching to the response data for [Angel3 framework](https://pub.dev/packages/angel3).
|
||||
A service that provides HTTP caching to the response data for [Protevus framework](https://pub.dev/packages/protevus).
|
||||
|
||||
## `CacheService`
|
||||
|
||||
A `Service` class that caches data from one service, storing it in another. An imaginable use case is storing results from MongoDB or another database in MemcacheD/Redis.
|
||||
A `Service` class that caches data from one service, storing it in another. An imaginable use case is storing results from MongoDB or another database in Memcache/Redis.
|
||||
|
||||
## `cacheSerializationResults`
|
||||
|
||||
|
@ -20,18 +19,18 @@ This can improve the performance of sending objects that are complex to serializ
|
|||
|
||||
```dart
|
||||
void main() async {
|
||||
var app = Angel()..lazyParseBodies = true;
|
||||
var app = Protevus()..lazyParseBodies = true;
|
||||
|
||||
app.use(
|
||||
'/api/todos',
|
||||
CacheService(
|
||||
database: AnonymousService(
|
||||
index: ([params]) {
|
||||
print('Fetched directly from the underlying service at ${new DateTime.now()}!');
|
||||
print('Fetched directly from the underlying service at ${DateTime.now()}!');
|
||||
return ['foo', 'bar', 'baz'];
|
||||
},
|
||||
read: (id, [params]) {
|
||||
return {id: '$id at ${new DateTime.now()}'};
|
||||
return {id: '$id at ${DateTime.now()}'};
|
||||
}
|
||||
),
|
||||
),
|
||||
|
@ -41,16 +40,16 @@ void main() async {
|
|||
|
||||
## `ResponseCache`
|
||||
|
||||
A flexible response cache for Angel3.
|
||||
A flexible response cache for Protevus.
|
||||
|
||||
Use this to improve real and perceived response of Web applications, as well as to memoize expensive responses.
|
||||
Use this to improve real and perceived response of Web applications, as well as to memorize expensive responses.
|
||||
|
||||
Supports the `If-Modified-Since` header, as well as storing the contents of response buffers in memory.
|
||||
|
||||
To initialize a simple cache:
|
||||
|
||||
```dart
|
||||
Future configureServer(Angel app) async {
|
||||
Future configureServer(Protevus app) async {
|
||||
// Simple instance.
|
||||
var cache = ResponseCache();
|
||||
|
||||
|
@ -82,10 +81,10 @@ Call `invalidate` to remove a resource from a `ResponseCache`.
|
|||
Some servers expect a reverse proxy or caching layer to support `PURGE` requests. If this is your case, make sure to include some sort of validation (maybe IP-based) to ensure no arbitrary attacker can hack your cache:
|
||||
|
||||
```dart
|
||||
Future configureServer(Angel app) async {
|
||||
Future configureServer(Protevus app) async {
|
||||
app.addRoute('PURGE', '*', (req, res) {
|
||||
if (req.ip != '127.0.0.1')
|
||||
throw AngelHttpException.forbidden();
|
||||
throw ProtevusHttpException.forbidden();
|
||||
return cache.purge(req.uri.path);
|
||||
});
|
||||
}
|
||||
|
|
5
packages/cache/analysis_options.yaml
vendored
5
packages/cache/analysis_options.yaml
vendored
|
@ -1,4 +1 @@
|
|||
include: package:pedantic/analysis_options.yaml
|
||||
analyzer:
|
||||
strong-mode:
|
||||
implicit-casts: false
|
||||
include: package:lints/recommended.yaml
|
10
packages/cache/example/cache_service.dart
vendored
10
packages/cache/example/cache_service.dart
vendored
|
@ -1,9 +1,9 @@
|
|||
import 'package:angel3_cache/angel3_cache.dart';
|
||||
import 'package:angel3_framework/angel3_framework.dart';
|
||||
import 'package:angel3_framework/http.dart';
|
||||
import 'package:protevus_cache/protevus_cache.dart';
|
||||
import 'package:protevus_framework/protevus_framework.dart';
|
||||
import 'package:protevus_framework/http.dart';
|
||||
|
||||
void main() async {
|
||||
var app = Angel();
|
||||
var app = Protevus();
|
||||
|
||||
app.use(
|
||||
'/api/todos',
|
||||
|
@ -18,7 +18,7 @@ void main() async {
|
|||
})),
|
||||
);
|
||||
|
||||
var http = AngelHttp(app);
|
||||
var http = ProtevusHttp(app);
|
||||
var server = await http.startServer('127.0.0.1', 3000);
|
||||
print('Listening at http://${server.address.address}:${server.port}');
|
||||
}
|
||||
|
|
Some files were not shown because too many files have changed in this diff Show more
Loading…
Reference in a new issue