verify method Null safety

Future<Authorization> verify(
  1. String? accessToken,
  2. {List<AuthScope>? scopesRequired}
)

Returns a Authorization for accessToken.

This method obtains an AuthToken for accessToken from delegate and then verifies that the token is valid. If the token is valid, an Authorization object is returned. Otherwise, an AuthServerException is thrown.

Implementation

Future<Authorization> verify(String? accessToken,
    {List<AuthScope>? scopesRequired}) async {
  if (accessToken == null) {
    throw AuthServerException(AuthRequestError.invalidRequest, null);
  }

  final AuthToken? t =
      await delegate.getToken(this, byAccessToken: accessToken);
  if (t == null || t.isExpired) {
    throw AuthServerException(
        AuthRequestError.invalidGrant, AuthClient(t!.clientID!, null, null));
  }

  if (scopesRequired != null) {
    if (!AuthScope.verify(scopesRequired, t.scopes!)) {
      throw AuthServerException(
          AuthRequestError.invalidScope, AuthClient(t.clientID!, null, null));
    }
  }

  return Authorization(t.clientID, t.resourceOwnerIdentifier, this,
      scopes: t.scopes);
}