addToken method
Must store token
.
token
must be stored such that it is accessible from getToken, and until it is either
revoked via removeToken or removeTokens, or until it has expired and can reasonably
be believed to no longer be in use.
You may alter token
prior to storing it. This may include replacing AuthToken.accessToken with another token
format. The default token format will be a random 32 character string.
If this token was granted through an authorization code, issuedFrom
is that code. Otherwise, issuedFrom
is null.
Implementation
@override
Future addToken(AuthServer server, AuthToken token,
{AuthCode? issuedFrom}) async {
final storage = ManagedAuthToken.fromToken(token);
final query = Query<ManagedAuthToken>(context)..values = storage;
if (issuedFrom != null) {
query.where((o) => o.code).equalTo(issuedFrom.code);
query.values!.code = issuedFrom.code;
final ManagedAuthToken? outToken = await query.updateOne();
if (outToken == null) {
throw AuthServerException(AuthRequestError.invalidGrant,
AuthClient(token.clientID!, null, null));
}
} else {
await query.insert();
}
return pruneTokens(token.resourceOwnerIdentifier);
}