addClient method
Creates a new OAuth2 client identifier and returns an Agent
that makes requests on behalf of that client.
A new AuthClient
is added to the authServer's database. Returns an Agent
that will
execute requests with a basic authorization header that contains id
and secret
.
If secret
is null, redirectUri
is ignored (public clients cannot have a redirect URI).
NOTE: This method adds rows to a database table managed by your test application and TestHarnessORMMixin.resetData will delete those rows. To ensure clients exist for all tests, add clients in TestHarnessORMMixin.seed.
Implementation
Future<Agent> addClient(String id,
{String? secret, String? redirectUri, List<String>? allowedScope}) async {
final client = AuthClient.public(id,
allowedScopes: allowedScope?.map((s) => AuthScope(s)).toList());
if (secret != null) {
client
..salt = AuthUtility.generateRandomSalt()
..hashedSecret = AuthUtility.generatePasswordHash(secret, client.salt)
..redirectURI = redirectUri!;
}
await authServer!.addClient(client);
final authorizationHeader =
"Basic ${base64.encode("$id:${secret ?? ""}".codeUnits)}";
return Agent.from(agent!)..headers["authorization"] = authorizationHeader;
}