Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: Celest Auth #52

Closed
wants to merge 36 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
36 commits
Select commit Hold shift + click to select a range
ee9481a
Initial auth runtime
dnys1 Mar 2, 2024
5d400a4
Create Auth protocol
dnys1 Mar 3, 2024
05924da
Continue passkey work
dnys1 Mar 4, 2024
072078c
Move cedar_common/corks to main repo
dnys1 Mar 4, 2024
f7bebee
Clean up and cancellation support
dnys1 Mar 4, 2024
68f562a
Refactor and add secure storage module
dnys1 Mar 4, 2024
7a13bc6
Move passkey exception impl to Auth
dnys1 Mar 4, 2024
7f1012d
Fix
dnys1 Mar 4, 2024
8bab527
Sketch out public interface
dnys1 Mar 4, 2024
afbcaff
Add email OTP
dnys1 Mar 5, 2024
4bfa8cf
clean up
dnys1 Mar 6, 2024
1ede4a9
Merge branch 'main' into feat/celest_auth
dnys1 Mar 6, 2024
ac3864f
Use secure storage from core
dnys1 Mar 6, 2024
c793fc3
Merge remote-tracking branch 'origin/main' into feat/celest_auth
dnys1 Mar 7, 2024
7413956
Merge remote-tracking branch 'origin/main' into feat/celest_auth
dnys1 Mar 7, 2024
392a00c
clean up
dnys1 Mar 7, 2024
73b11d7
Align memstorage interface
dnys1 Mar 7, 2024
dc8d2de
Update flow types
dnys1 Mar 7, 2024
8c5a43b
Add back Auth provider types
dnys1 Mar 8, 2024
c02900b
Add proper Auth example
dnys1 Mar 8, 2024
fdf4070
Make Cedar types built_value representable
dnys1 Mar 8, 2024
2726410
Add back @public
dnys1 Mar 8, 2024
5455826
Refactor Auth and create common Celest interface
dnys1 Mar 8, 2024
20fcbdb
Finish runtime
dnys1 Mar 8, 2024
9dda3fc
Cedar cleanup
dnys1 Mar 8, 2024
5a7c4f9
Add user context
dnys1 Mar 9, 2024
b1a3bcd
Fix init
dnys1 Mar 9, 2024
b17a7ed
Fix runtime
dnys1 Mar 9, 2024
231651d
Rename cedar_common to cedar_core
dnys1 Mar 9, 2024
a843a89
Improve security of corks
dnys1 Mar 9, 2024
6b03d74
Rename cedar_core to cedar
dnys1 Mar 9, 2024
7bbe42d
Add authorizer interface to cedar
dnys1 Mar 9, 2024
0963cca
add back annotation
dnys1 Mar 9, 2024
e53bca4
clean up
dnys1 Mar 9, 2024
0a1a770
workaround nullability issue
dnys1 Mar 9, 2024
3ef8df6
fix type url
dnys1 Mar 9, 2024
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
The table of contents is too big for display.
Diff view
Diff view
  •  
  •  
  •  
7 changes: 7 additions & 0 deletions packages/cedar/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
# https://dart.dev/guides/libraries/private-files
# Created by `dart pub`
.dart_tool/

# Avoid committing pubspec.lock for library packages; see
# https://dart.dev/guides/libraries/private-files#pubspeclock.
pubspec.lock
3 changes: 3 additions & 0 deletions packages/cedar/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
## 0.1.0

- Initial version.
5 changes: 5 additions & 0 deletions packages/cedar/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
# cedar

Base types and utilities of the Cedar language in Dart.

This is separate from `package:cedar` so that the types can be used without bundling the native assets of `package:cedar`.
30 changes: 30 additions & 0 deletions packages/cedar/analysis_options.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
# This file configures the static analysis results for your project (errors,
# warnings, and lints).
#
# This enables the 'recommended' set of lints from `package:lints`.
# This set helps identify many issues that may lead to problems when running
# or consuming Dart code, and enforces writing Dart using a single, idiomatic
# style and format.
#
# If you want a smaller set of lints you can change this to specify
# 'package:lints/core.yaml'. These are just the most critical lints
# (the recommended set includes the core lints).
# The core lints are also what is used by pub.dev for scoring packages.

include: package:lints/recommended.yaml

# Uncomment the following section to specify additional rules.

# linter:
# rules:
# - camel_case_types

# analyzer:
# exclude:
# - path/to/excluded/files/**

# For more information about the core and recommended set of lints, see
# https://dart.dev/go/core-lints

# For additional information about configuring this file, see
# https://dart.dev/guides/language/analysis-options
17 changes: 17 additions & 0 deletions packages/cedar/lib/cedar.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
/// Core types and interfaces of the Cedar policy language in Dart.
///
/// This is separate from `package:cedar_ffi` so that the types can be used
/// without bundling the native assets of `package:cedar_ffi`.
library;

export 'src/ast/cedar_entity.dart';
export 'src/ast/cedar_entity_id.dart';
export 'src/ast/cedar_node.dart';
export 'src/ast/cedar_schema.dart';
export 'src/authorization/cedar_authorization_request.dart';
export 'src/authorization/cedar_authorization_response.dart';
export 'src/authorization/cedar_authorizer.dart';
export 'src/policy/cedar_policy.dart';
export 'src/policy/cedar_policy_set.dart';
export 'src/policy/json_expr.dart';
export 'src/serializers.dart';
54 changes: 54 additions & 0 deletions packages/cedar/lib/src/ast/cedar_entity.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
import 'package:built_collection/built_collection.dart';
import 'package:built_value/built_value.dart';
import 'package:built_value/serializer.dart';
import 'package:cedar/src/ast/cedar_entity_id.dart';
import 'package:cedar/src/ast/cedar_node.dart';
import 'package:cedar/src/policy/json_expr.dart';

part 'cedar_entity.g.dart';

abstract class CedarEntity
implements Built<CedarEntity, CedarEntityBuilder>, CedarNode {
factory CedarEntity({
required CedarEntityId id,
List<CedarEntityId> parents = const [],
Map<String, CedarValueJson> attributes = const {},
}) {
return _$CedarEntity._(
id: id,
parents: parents.build(),
attributes: attributes.build(),
);
}

factory CedarEntity.build([
void Function(CedarEntityBuilder) updates,
]) = _$CedarEntity;

factory CedarEntity.fromJson(Map<String, Object?> json) => CedarEntity(
id: CedarEntityId.fromJson(json['uid'] as Map<String, Object?>),
parents: (json['parents'] as List<Object?>)
.map((e) => CedarEntityId.fromJson(e as Map<String, Object?>))
.toList(),
attributes: (json['attrs'] as Map<Object?, Object?>)
.cast<String, Object?>()
.map((key, value) => MapEntry(key, CedarValueJson.fromJson(value))),
);

const CedarEntity._();

CedarEntityId get id;
BuiltList<CedarEntityId> get parents;
BuiltMap<String, CedarValueJson> get attributes;

@override
Map<String, Object?> toJson() => {
'uid': id.toJson(),
'parents': parents.map((e) => e.toJson()).toList(),
'attrs': attributes
.map((key, value) => MapEntry(key, value.toJson()))
.asMap(),
};

static Serializer<CedarEntity> get serializer => _$cedarEntitySerializer;
}
201 changes: 201 additions & 0 deletions packages/cedar/lib/src/ast/cedar_entity.g.dart

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

70 changes: 70 additions & 0 deletions packages/cedar/lib/src/ast/cedar_entity_id.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,70 @@
import 'package:built_value/built_value.dart';
import 'package:built_value/serializer.dart';
import 'package:cedar/src/ast/cedar_node.dart';

part 'cedar_entity_id.g.dart';

abstract class CedarEntityId
implements Built<CedarEntityId, CedarEntityIdBuilder>, CedarNode {
factory CedarEntityId(String type, String id) =>
_$CedarEntityId._(type: type, id: id);

factory CedarEntityId.build([
void Function(CedarEntityIdBuilder) updates,
]) = _$CedarEntityId;

factory CedarEntityId.fromJson(Map<String, Object?> json) {
switch (json) {
case {'type': final String type, 'id': final String id} ||
{'__entity': {'type': final String type, 'id': final String id}}:
return CedarEntityId(type, id);
default:
throw FormatException('Invalid entity ID JSON: $json');
}
}

const CedarEntityId._();

String get type;
String get id;

/// Returns a normalized version of this entity ID.
///
/// Cedar prohibits whitespace in entity IDs, so this method removes all
/// whitespace from the [type] and [id].
///
/// See [RFC 9](https://github.com/cedar-policy/rfcs/blob/main/text/0009-disallow-whitespace-in-entityuid.md)
/// for more information.
CedarEntityId get normalized => CedarEntityId(
type,
String.fromCharCodes(
id.runes.expand((char) {
return switch (char) {
0 => '\\0'.codeUnits,
0x9 => '\\t'.codeUnits,
0xa => '\\n'.codeUnits,
0xd => '\\r'.codeUnits,
0x22 => '\\"'.codeUnits,
0x27 => "\\'".codeUnits,
< 0x20 ||
0x7f || // Delete
0x96 || // Non-breaking space
> 0xffff =>
'\\u{${char.toRadixString(16)}}'.codeUnits,
_ => [char],
};
}),
),
);

@override
String toString() => '$type::"$id"';

@override
Map<String, Object?> toJson() => {
'type': type,
'id': id,
};

static Serializer<CedarEntityId> get serializer => _$cedarEntityIdSerializer;
}
Loading
Loading