feat: Add constant WebID extractor.

Closes https://github.com/solid/community-server/issues/397
This commit is contained in:
Ruben Verborgh
2020-12-17 22:40:28 +01:00
committed by Joachim Van Herwegen
parent 3e3dd7f5a9
commit 209b87a424
2 changed files with 37 additions and 0 deletions

View File

@@ -0,0 +1,22 @@
import { getLoggerFor } from '../logging/LogUtil';
import type { Credentials } from './Credentials';
import { CredentialsExtractor } from './CredentialsExtractor';
/**
* Credentials extractor that authenticates a constant agent
* (useful for development or debugging purposes).
*/
export class UnsecureConstantCredentialsExtractor extends CredentialsExtractor {
private readonly agent: Credentials;
private readonly logger = getLoggerFor(this);
public constructor(agent: string | Credentials) {
super();
this.agent = typeof agent === 'string' ? { webId: agent } : agent;
}
public async handle(): Promise<Credentials> {
this.logger.info(`Agent unsecurely claims to be ${this.agent.webId}`);
return this.agent;
}
}