configureProtectedResource method

void configureProtectedResource({
  1. required String resource,
  2. required List<String> authorizationServers,
  3. List<String>? scopesSupported,
  4. List<String>? bearerMethodsSupported,
  5. String? resourceDocumentation,
})

Configure the OAuth Protected Resource metadata served at /.well-known/oauth-protected-resource (RFC 9728).

Implementation

void configureProtectedResource({
  required String resource,
  required List<String> authorizationServers,
  List<String>? scopesSupported,
  List<String>? bearerMethodsSupported,
  String? resourceDocumentation,
}) {
  final uri = Uri.tryParse(resource);
  if (uri == null || !uri.hasScheme || !uri.hasAuthority || uri.hasFragment) {
    throw ArgumentError.value(
      resource,
      'resource',
      'must be an absolute URI without a fragment',
    );
  }
  if (authorizationServers.isEmpty) {
    throw ArgumentError.value(
      authorizationServers,
      'authorizationServers',
      'must name at least one',
    );
  }
  _protectedResource = _ProtectedResourceMetadata(
    resource: resource,
    authorizationServers: List.unmodifiable(authorizationServers),
    // Refresh tokens are not a resource requirement.
    scopesSupported:
        scopesSupported == null
            ? null
            : List.unmodifiable(
              scopesSupported.where((s) => s != 'offline_access'),
            ),
    bearerMethodsSupported:
        bearerMethodsSupported == null
            ? null
            : List.unmodifiable(bearerMethodsSupported),
    resourceDocumentation: resourceDocumentation,
  );
}