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: at_auth package #428

Merged
merged 6 commits into from
Oct 13, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 10 additions & 0 deletions packages/at_auth/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
# https://dart.dev/guides/libraries/private-files
# Created by `dart pub`
.dart_tool/
.packages

# Avoid committing pubspec.lock for library packages; see
# https://dart.dev/guides/libraries/private-files#pubspeclock.
pubspec.lock

at_auth.iml
2 changes: 2 additions & 0 deletions packages/at_auth/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
## 1.0.0
- Implemented onboard and authenticate methods.
33 changes: 33 additions & 0 deletions packages/at_auth/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
Package for onboarding and authentication to an atsign's secondary server

## Features

- onboard logic - cram authentication,pkam/encryption/apkam key pair generation, initial pkam authentication
- authentication - read keys from .atKeys file, pkam authentication

## Getting started

- Developers should have a free/paid atsign from https://atsign.com/

## Usage

Onboard an atsign
```dart
final atAuth = AtAuthImpl();
final atOnboardingRequest = AtOnboardingRequest('@alice')
..rootDomain = 'vip.ve.atsign.zone'
..enableEnrollment = true
..appName = 'wavi'
..deviceName = 'iphone';
final atOnboardingResponse = await atAuth.onboard(atOnboardingRequest, <cram_secret>);
```

Authenticate an atsign
```dart
final atAuth = AtAuthImpl();
final atAuthRequest = AtAuthRequest('@alice')
..rootDomain = 'vip.ve.atsign.zone'
..atKeysFilePath = args[1];
final atAuthResponse = await atAuth.authenticate(atAuthRequest);
```

34 changes: 34 additions & 0 deletions packages/at_auth/analysis_options.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
# 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 : true
unnecessary_string_interpolations : true
await_only_futures : true
unawaited_futures: true
depend_on_referenced_packages : false

# 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
12 changes: 12 additions & 0 deletions packages/at_auth/example/authenticate.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
import 'package:at_auth/at_auth.dart';

/// dart authenticate.dart <atsign> <path_to_atkeys_file>
void main(List<String> args) async {
final atAuth = AtAuthImpl();
final atSign = args[0];
final atAuthRequest = AtAuthRequest(atSign)
..rootDomain = 'vip.ve.atsign.zone'
..atKeysFilePath = args[1];
final atAuthResponse = await atAuth.authenticate(atAuthRequest);
print('atAuthResponse: $atAuthResponse');
}
15 changes: 15 additions & 0 deletions packages/at_auth/example/onboard_apkam.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
import 'package:at_auth/at_auth.dart';

/// dart onboard_apkam.dart <atsign> <cram_secret>
void main(List<String> args) async {
final atAuth = AtAuthImpl();
final atSign = args[0];
final atOnboardingRequest = AtOnboardingRequest(atSign)
..rootDomain = 'vip.ve.atsign.zone'
..enableEnrollment = true
..appName = 'wavi'
..deviceName = 'iphone';
final atOnboardingResponse =
await atAuth.onboard(atOnboardingRequest, args[1]);
print('atOnboardingResponse: $atOnboardingResponse');
}
12 changes: 12 additions & 0 deletions packages/at_auth/example/onboard_legacy.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
import 'package:at_auth/at_auth.dart';

/// dart onboard_legacy.dart <atsign> <cram_secret>
void main(List<String> args) async {
final atAuth = AtAuthImpl();
final atSign = args[0];
final atOnboardingRequest = AtOnboardingRequest(atSign)
..rootDomain = 'vip.ve.atsign.zone';
final atOnboardingResponse =
await atAuth.onboard(atOnboardingRequest, args[1]);
print('atOnboardingResponse: $atOnboardingResponse');
}
10 changes: 10 additions & 0 deletions packages/at_auth/lib/at_auth.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
library at_auth;

export 'src/at_auth_base.dart';
export 'src/at_auth_impl.dart';
export 'src/onboard/at_onboarding_request.dart';
export 'src/onboard/at_onboarding_response.dart';
export 'src/auth/at_auth_request.dart';
export 'src/auth/at_auth_response.dart';
export 'src/keys/at_auth_keys.dart';
export 'src/exception/at_auth_exceptions.dart';
25 changes: 25 additions & 0 deletions packages/at_auth/lib/src/at_auth_base.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
import 'package:at_auth/src/onboard/at_onboarding_request.dart';
import 'package:at_auth/src/onboard/at_onboarding_response.dart';
import 'package:at_auth/src/auth/at_auth_request.dart';
import 'package:at_auth/src/auth/at_auth_response.dart';
import 'package:at_chops/at_chops.dart';

/// Interface for onboarding and authentication to a secondary server of an atsign
abstract class AtAuth {
AtChops? atChops;

/// Authenticate method is invoked when an atsign wants to authenticate to secondary server with an .atKeys file
/// Step 1. Read the keys from [atAuthRequest.atAuthKeys] or [atAuthRequest.atKeysFilePath]
/// Step 2 Perform pkam authentication
Future<AtAuthResponse> authenticate(AtAuthRequest atAuthRequest);

/// Onboard method is invoked when an atsign is activated for the first time from a client app.
/// Step 1. Perform cram auth
/// Step 2. Generate pkam, encryption keypairs and apkam symmetric key
/// Step 3. Update pkam public key to secondary
/// Step 4. Perform pkam auth
/// Step 5. Update encryption public key to server and delete cram secret from server
/// Set [atOnboardingRequest.publicKeyId] if pkam auth mode is [PkamAuthMode.sim]
Future<AtOnboardingResponse> onboard(
AtOnboardingRequest atOnboardingRequest, String cramSecret);
}
Loading