It appears that the authenticationProvider
is missing for some reason.
@autoinject()
export class ProviderManager implements AuthenticationManager {
constructor( private container: Container ){
}
public authenticate( creds: Credentials ): Promise<Authentication> {
var provider = creds.authenticationProvider();
return this.container.get( provider ).authenticate( creds );
}
}
Credentials
export interface Credentials {
authenticationProvider(): { new(): AuthenticationManager };
}
the implementation of UsernamePasswordCredentials
export class UsernamePasswordCredentials implements Credentials {
public authenticationProvider(): {new(): AuthenticationManager} {
return HttpBasicAuthentication;
}
user: String;
pass: String;
}
AuthenticationManager
export interface AuthenticationManager {
authenticate( creds: Credentials ): Promise<Authentication>;
}
Login
@autoinject()
export class Login {
private log: Logger = LogManager.getLogger( Login );
creds: UsernamePasswordCredentials;
constructor( private am: AuthenticationManager, private router: Router ) {
}
public signIn(): void {
this.log.debug( `authenticating ${ this.creds.user }` );
this.am.authenticate( this.creds ).then( auth => {
var route = Route.MANAGE_CONTENT;
this.log.debug( `navigating to ${ route }` );
var router = this.router;
router.navigate( route );
} ).catch( error => {
this.log.error( error );
} );
}
}
This is the stacktrace from Chrome:
VM802:1 Uncaught TypeError: creds.authenticationProvider is not a function(…)(anonymous function) @ VM802:1
authenticate @ ProviderManager.ts:13
signIn @ login.ts:22evaluate @ aurelia-binding.js:1522
callSource @ aurelia-binding.js:4963
(anonymous function) @ aurelia-binding.js:4987
handleDelegatedEvent @ aurelia-binding.js:3176