Skip to content

GSOC API Auth Draft-PR #776

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

Closed
wants to merge 8 commits into from
Closed
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
22 changes: 22 additions & 0 deletions lib/consts.dart
Original file line number Diff line number Diff line change
Expand Up @@ -163,6 +163,27 @@ enum ResponseBodyView {
final IconData icon;
}

enum AuthType {
noauth("No Auth"),
basic("Basic"),
bearer("Bearer"),
apikey("API Key"),
digest("Digest"),
oauth1("OAuth 1.0"),
oauth2("OAuth 2.0");

const AuthType(this.label);
final String label;
}

enum AddTo {
header("Header"),
query("Query Parameter");

const AddTo(this.label);
final String label;
}

const kNoBodyViewOptions = [ResponseBodyView.none];
const kNoRawBodyViewOptions = [ResponseBodyView.none, ResponseBodyView.raw];
const kRawBodyViewOptions = [ResponseBodyView.raw];
Expand Down Expand Up @@ -445,6 +466,7 @@ const kLabelURLParams = "URL Params";
const kLabelHeaders = "Headers";
const kLabelBody = "Body";
const kLabelQuery = "Query";
const kLabelAuthorization = "Authorization";
const kNameCheckbox = "Checkbox";
const kNameURLParam = "URL Parameter";
const kNameHeader = "Header Name";
Expand Down
79 changes: 79 additions & 0 deletions lib/models/authorization_model.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,79 @@
import 'package:apidash/consts.dart';
import 'package:apidash_core/apidash_core.dart';

part 'authorization_model.freezed.dart';

part 'authorization_model.g.dart';

@freezed
class AuthorizationModel with _$AuthorizationModel {
@JsonSerializable(
explicitToJson: true,
anyMap: true,
)
const factory AuthorizationModel({
@Default(AuthType.noauth) AuthType authType,
@Default(BasicAuthModel(username: '', password: '')) BasicAuthModel basicAuthModel,
@Default(BearerAuthModel(token: '')) BearerAuthModel bearerAuthModel,
@Default(ApiKeyAuthModel(key: '', value: '', addTo: AddTo.header)) ApiKeyAuthModel apiKeyAuthModel,
// JWTBearerAuthModel? jwtBearerAuthModel,
// DigestAuthModel? digestAuthModel,
// OAuth1AuthModel? oauth1AuthModel,
// OAuth2AuthModel? oauth2AuthModel,
}) = _AuthorizationModel;

factory AuthorizationModel.fromJson(Map<String, Object?> json) =>
_$AuthorizationModelFromJson(json);
}

@freezed
class BasicAuthModel with _$BasicAuthModel {
@JsonSerializable(
explicitToJson: true,
anyMap: true,
)
const factory BasicAuthModel({
@Default("") String username,
@Default("") String password,
}) = _BasicAuthModel;

factory BasicAuthModel.fromJson(Map<String, Object?> json) =>
_$BasicAuthModelFromJson(json);
}

@freezed
class BearerAuthModel with _$BearerAuthModel {
@JsonSerializable(
explicitToJson: true,
anyMap: true,
)
const factory BearerAuthModel({
@Default("") String token,
}) = _BearerAuthModel;

factory BearerAuthModel.fromJson(Map<String, Object?> json) =>
_$BearerAuthModelFromJson(json);
}

@freezed
class ApiKeyAuthModel with _$ApiKeyAuthModel {
@JsonSerializable(
explicitToJson: true,
anyMap: true,
)
const factory ApiKeyAuthModel({
@Default("") String key,
@Default("") String value,
@Default(AddTo.header) AddTo addTo,
}) = _ApiKeyAuthModel;

factory ApiKeyAuthModel.fromJson(Map<String, Object?> json) =>
_$ApiKeyAuthModelFromJson(json);
}

// @freezed
// class DigestAuthModel with _$DigestAuthModel {
// @JsonSerializable(
// explicitToJson: true,
// anyMap: true,
// )
Loading