Skip to content

Commit

Permalink
feat(auth): adds runtime inference for org auth
Browse files Browse the repository at this point in the history
  • Loading branch information
eljefedelrodeodeljefe committed Dec 18, 2018
1 parent 2cc1142 commit 9cdada8
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 1 deletion.
8 changes: 7 additions & 1 deletion src/v0/auth.ts
Expand Up @@ -5,7 +5,8 @@ import { Client, ClientOptions } from '../client'
export enum AuthTypes {
username = 1,
key,
token
token,
org
}

export interface AuthOptions {
Expand Down Expand Up @@ -48,6 +49,10 @@ export function isTokenAuth(object: any): object is KeyAuth {
return 'token' in object
}

export function isOrgAuth(object: any): object is KeyAuth {
return 'organisation' in object
}

export interface AuthResponse {
token: string
user: string
Expand Down Expand Up @@ -82,6 +87,7 @@ export class Auth {
if (isUsernameAuth(this.options.credentials)) this.options.type = AuthTypes.username
if (isKeyAuth(this.options.credentials)) this.options.type = AuthTypes.key
if (isTokenAuth(this.options.credentials)) this.options.type = AuthTypes.token
if (isOrgAuth(this.options.credentials)) this.options.type = AuthTypes.org
}

async authenticate(): Promise<AuthResponse> {
Expand Down
4 changes: 4 additions & 0 deletions src/v1/auth.ts
Expand Up @@ -42,6 +42,10 @@ export class Auth extends v0.Auth {
return this.loginServiceAccount(this.options.credentials as KeyAuth)
}

if (this.options.type === AuthTypes.org) {
return this.loginWithOrganisation(this.options.credentials as OrgAuth)
}

throw new errors.AuthenticationFailed('No auth data was provided')
}

Expand Down

0 comments on commit 9cdada8

Please sign in to comment.