Skip to content

Implement OIDC Authentication Support #167

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Jan 15, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 20 additions & 0 deletions src/oidc_auth.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
import { Authenticator } from './auth';
import { User } from './config_types';

export class OpenIDConnectAuth implements Authenticator {
public isAuthProvider(user: User): boolean {
if (!user.authProvider) {
return false;
}
return user.authProvider.name === 'oidc';
}

public getToken(user: User): string | null {
if (!user.authProvider.config || !user.authProvider.config['id-token']) {
return null;
}
// TODO: Handle expiration and refresh here...
// TODO: Extract the 'Bearer ' to config.ts?
return `Bearer ${user.authProvider.config['id-token']}`;
}
}
59 changes: 59 additions & 0 deletions src/oidc_auth_test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
import { expect } from 'chai';

import { User } from './config_types';
import { OpenIDConnectAuth } from './oidc_auth';

describe('OIDCAuth', () => {
const auth = new OpenIDConnectAuth();
it('should be true for oidc user', () => {
const user = {
authProvider: {
name: 'oidc',
},
} as User;

expect(auth.isAuthProvider(user)).to.equal(true);
});

it('should be false for other user', () => {
const user = {
authProvider: {
name: 'azure',
},
} as User;

expect(auth.isAuthProvider(user)).to.equal(false);
});

it('should be false for null user.authProvider', () => {
const user = {} as User;

expect(auth.isAuthProvider(user)).to.equal(false);
});

it('get a token if present', () => {
const token = 'some token';
const user = {
authProvider: {
name: 'oidc',
config: {
'id-token': token,
},
},
} as User;

expect(auth.getToken(user)).to.equal(`Bearer ${token}`);
});

it('get null if token missing', () => {
const user = {
authProvider: {
name: 'oidc',
config: {
},
},
} as User;

expect(auth.getToken(user)).to.equal(null);
});
});