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

Feature/device code flow #78

Open
wants to merge 9 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 5 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
26 changes: 26 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -175,7 +175,33 @@ authenticate(Uri uri, String clientId, List<String> scopes) async {
}
```

### Usage example flutter - device code flow

```dart

/// Define a callback to be called once user completes the flow
Function(Credential? credentials) callback = (credentials) => print(credentials.toString());

/// Example parameters
var authServerUrl = "https://localhost";
var clientId = "clientid";
var clientSecret = "clientSecret";
var scopes = ["openid","email","profile"];

var _issuer = await Issuer.discover(Uri.parse(authServerUrl));
var _client = Client(
_issuer,
clientId,
clientSecret: clientSecret,
);
var _flow = Flow.device(
_client,
scopes: scopes,
);

/// this will get the device code to show to user and will call the callback when the user completed the flow
var deviceCode = await _flow.getDeviceCode((credentials) => callback(credentials));
```


## Command line tool
Expand Down
36 changes: 14 additions & 22 deletions lib/src/model/metadata.dart
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,9 @@ class OpenIdProviderMetadata extends JsonObject {
/// URL of the OP's UserInfo Endpoint.
Uri? get userinfoEndpoint => getTyped('userinfo_endpoint');

/// URL of the OP's Device Authorization Endpoint
Uri? get deviceAuthorizationEndpoint => getTyped('device_authorization_endpoint');

/// URL of the OP's JSON Web Key Set document.
///
/// This contains the signing key(s) the RP uses to validate signatures from the OP.
Expand All @@ -26,25 +29,21 @@ class OpenIdProviderMetadata extends JsonObject {
List<String>? get scopesSupported => getTypedList('scopes_supported');

/// A list of the OAuth 2.0 `response_type` values that this OP supports.
List<String> get responseTypesSupported =>
getTypedList('response_types_supported')!;
List<String> get responseTypesSupported => getTypedList('response_types_supported')!;

/// A list of the OAuth 2.0 `response_mode` values that this OP supports.
List<String>? get responseModesSupported =>
getTypedList('response_modes_supported');
List<String>? get responseModesSupported => getTypedList('response_modes_supported');

/// A list of the OAuth 2.0 Grant Type values that this OP supports.
List<String>? get grantTypesSupported =>
getTypedList('grant_types_supported');
List<String>? get grantTypesSupported => getTypedList('grant_types_supported');

/// A list of the Authentication Context Class References that this OP supports.
List<String>? get acrValuesSupported => getTypedList('acr_values_supported');

/// A list of the Subject Identifier types that this OP supports.
///
/// Valid types include `pairwise` and `public`.
List<String> get subjectTypesSupported =>
getTypedList('subject_types_supported')!;
List<String> get subjectTypesSupported => getTypedList('subject_types_supported')!;

/// A list of the JWS signing algorithms (`alg` values) supported by the OP for
/// the ID Token to encode the Claims in a JWT.
Expand Down Expand Up @@ -122,15 +121,13 @@ class OpenIdProviderMetadata extends JsonObject {
getTypedList('token_endpoint_auth_signing_alg_values_supported');

/// A list of the display parameter values that the OpenID Provider supports.
List<String>? get displayValuesSupported =>
getTypedList('display_values_supported');
List<String>? get displayValuesSupported => getTypedList('display_values_supported');

/// A list of the Claim Types that the OpenID Provider supports.
///
/// Values defined by the specification are `normal`, `aggregated`, and
/// `distributed`. If omitted, the implementation supports only `normal` Claims.
List<String>? get claimTypesSupported =>
getTypedList('claim_types_supported');
List<String>? get claimTypesSupported => getTypedList('claim_types_supported');

/// A list of the Claim Names of the Claims that the OpenID Provider MAY be
/// able to supply values for.
Expand All @@ -146,28 +143,23 @@ class OpenIdProviderMetadata extends JsonObject {
/// Languages and scripts supported for values in Claims being returned.
///
/// Not all languages and scripts are necessarily supported for all Claim values.
List<String>? get claimsLocalesSupported =>
getTypedList('claims_locales_supported');
List<String>? get claimsLocalesSupported => getTypedList('claims_locales_supported');

/// Languages and scripts supported for the user interface.
List<String>? get uiLocalesSupported => getTypedList('ui_locales_supported');

/// `true` when the OP supports use of the `claims` parameter.
bool get claimsParameterSupported =>
this['claims_parameter_supported'] ?? false;
bool get claimsParameterSupported => this['claims_parameter_supported'] ?? false;

/// `true` when the OP supports use of the `request` parameter.
bool get requestParameterSupported =>
this['request_parameter_supported'] ?? false;
bool get requestParameterSupported => this['request_parameter_supported'] ?? false;

/// `true` when the OP supports use of the `request_uri` parameter.
bool get requestUriParameterSupported =>
this['request_uri_parameter_supported'] ?? true;
bool get requestUriParameterSupported => this['request_uri_parameter_supported'] ?? true;

/// `true` when the OP requires any `request_uri` values used to be
/// pre-registered using the request_uris registration parameter.
bool get requireRequestUriRegistration =>
this['require_request_uri_registration'] ?? false;
bool get requireRequestUriRegistration => this['require_request_uri_registration'] ?? false;

/// URL that the OpenID Provider provides to the person registering the Client
/// to read about the OP's requirements on how the Relying Party can use the
Expand Down
Loading