-
Notifications
You must be signed in to change notification settings - Fork 3
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
Intergrate Authorisation into embedded ui #311
Merged
Merged
Changes from all commits
Commits
Show all changes
16 commits
Select commit
Hold shift + click to select a range
f250bf0
WIP
richard-cox 6e78815
use user in auth requests to epinio, start tidying up flow
richard-cox 99396b1
fix a number of things
richard-cox c7bf1c4
support local auth as well
richard-cox d61d725
started removing todos
richard-cox 672f753
more todos
richard-cox c88b714
tidying up
richard-cox ae82067
apply new info / me changes
richard-cox a6bc810
Fix build epinio pkg
richard-cox 80f37fb
Fix initialisation of cluster model & re-enter once locally logged in
richard-cox 2d6100a
Fix lint, changes after self review
richard-cox c3bef11
Fix redirect, remove useless pagination stuff
richard-cox 1bea25a
Fix #361
richard-cox 2473e74
Remove unused query params from verify
richard-cox d5b3da1
bump shell
richard-cox a3c3937
Temporarily add typing for is-url
richard-cox File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,199 @@ | ||
<script> | ||
import GenericPrompt from '@shell/dialog/GenericPrompt'; | ||
import Tabbed from '@shell/components/Tabbed/index.vue'; | ||
import Tab from '@shell/components/Tabbed/Tab.vue'; | ||
import epinioAuth, { EpinioAuthTypes } from '../utils/auth'; | ||
import Password from '@shell/components/form/Password'; | ||
import { LabeledInput } from '@components/Form/LabeledInput'; | ||
|
||
export default { | ||
name: 'LoginDialog', | ||
|
||
components: { | ||
GenericPrompt, Tabbed, Tab, LabeledInput, Password | ||
}, | ||
|
||
props: { | ||
resources: { | ||
type: Array, | ||
required: true | ||
} | ||
}, | ||
|
||
data() { | ||
return { | ||
selectedTab: '', | ||
username: '', | ||
password: '', | ||
config: { | ||
applyMode: 'login', | ||
applyAction: this.login, | ||
}, | ||
tab: { | ||
local: 'local', | ||
dex: 'dex' | ||
} | ||
}; | ||
}, | ||
|
||
computed: { | ||
cluster() { | ||
return this.resources[0]; | ||
} | ||
}, | ||
|
||
mounted() { | ||
if (!this.cluster.oidcEnabled) { | ||
this.selectedTab = this.tab.local; | ||
} | ||
}, | ||
|
||
methods: { | ||
async login() { | ||
const errors = []; | ||
|
||
switch (this.selectedTab) { | ||
case this.tab.local: | ||
if (!this.username) { | ||
errors.push('Username'); | ||
} | ||
if (!this.password) { | ||
errors.push('Password'); | ||
} | ||
if (errors.length) { | ||
return Promise.reject(new Error(`${ errors.join('/') } Required`)); | ||
} | ||
|
||
await epinioAuth.login(this.cluster.createAuthConfig(EpinioAuthTypes.LOCAL, { | ||
username: this.username, | ||
password: this.password, | ||
$axios: this.$axios, | ||
})); | ||
break; | ||
case this.tab.dex: | ||
await epinioAuth.login(this.cluster.createAuthConfig(EpinioAuthTypes.DEX)); | ||
|
||
break; | ||
default: | ||
throw new Error(`Unknown log in type: ${ this.selectedTab }`); | ||
} | ||
|
||
this.cluster.loggedIn = true; | ||
|
||
this.$router.push({ | ||
name: 'epinio-c-cluster-dashboard', | ||
params: { cluster: this.cluster.id } | ||
}); | ||
}, | ||
|
||
tabChanged({ selectedName }) { | ||
this.selectedTab = selectedName; | ||
}, | ||
|
||
close() { | ||
this.$emit('close', false); | ||
} | ||
} | ||
}; | ||
</script> | ||
|
||
<template> | ||
<GenericPrompt | ||
v-bind="config" | ||
@close="close" | ||
> | ||
<h4 | ||
slot="title" | ||
class="text-default-text login-dialog__title" | ||
> | ||
{{ t('epinio.login.modal.title') }} | ||
</h4> | ||
|
||
<template slot="body"> | ||
<Tabbed | ||
v-if="cluster.oidcEnabled" | ||
@changed="tabChanged" | ||
> | ||
<Tab | ||
label-key="epinio.login.modal.local.tabLabel" | ||
:name="tab.local" | ||
:weight="3" | ||
class="login-dialog__tab" | ||
> | ||
<form> | ||
<div class="span-10 offset-1"> | ||
<div class="mb-20"> | ||
<LabeledInput | ||
id="username" | ||
ref="username" | ||
v-model.trim="username" | ||
data-testid="local-login-username" | ||
:label="t('login.username')" | ||
autocomplete="epinio-username" | ||
:required="true" | ||
/> | ||
</div> | ||
<div class=""> | ||
<Password | ||
id="password" | ||
ref="password" | ||
v-model="password" | ||
data-testid="local-login-password" | ||
:label="t('login.password')" | ||
autocomplete="epinio-password" | ||
:required="true" | ||
/> | ||
</div> | ||
</div> | ||
</form> | ||
</Tab> | ||
<Tab | ||
label-key="epinio.login.modal.dex.tabLabel" | ||
:name="tab.dex" | ||
:weight="2" | ||
class="login-dialog__tab" | ||
> | ||
<p> | ||
{{ t('epinio.login.modal.dex.prompt') }} | ||
</p> | ||
</Tab> | ||
</Tabbed> | ||
<form v-else> | ||
<div class="span-10 offset-1 mt-15"> | ||
<div class="mb-20"> | ||
<LabeledInput | ||
id="username" | ||
ref="username" | ||
v-model.trim="username" | ||
data-testid="local-login-username" | ||
:label="t('login.username')" | ||
autocomplete="epinio-username" | ||
:required="true" | ||
/> | ||
</div> | ||
<div class=""> | ||
<Password | ||
id="password" | ||
ref="password" | ||
v-model="password" | ||
data-testid="local-login-password" | ||
:label="t('login.password')" | ||
autocomplete="epinio-password" | ||
:required="true" | ||
/> | ||
</div> | ||
</div> | ||
</form> | ||
</template> | ||
</GenericPrompt> | ||
</template> | ||
<style lang='scss' scoped> | ||
.login-dialog { | ||
&__title { | ||
margin-bottom: 0; | ||
} | ||
&__tab { | ||
min-height: 145px; | ||
} | ||
} | ||
</style> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,81 @@ | ||
import Resource from '@shell/plugins/dashboard-store/resource-class'; | ||
import { EPINIO_TYPES } from '../types'; | ||
import epinioAuth, { EpinioAuthConfig, EpinioAuthLocalConfig, EpinioAuthTypes } from '../utils/auth'; | ||
|
||
export const EpinioInfoPath = `/api/v1/info`; | ||
|
||
export default class EpinioCluster extends Resource { | ||
type = EPINIO_TYPES.CLUSTER; | ||
|
||
id: string; | ||
name: string; | ||
state?: string; | ||
metadata?: { state: { transitioning: boolean, error: boolean, message: string }}; | ||
loggedIn: boolean; | ||
api: string; | ||
mgmtCluster: any; | ||
oidcEnabled: boolean = false; | ||
|
||
constructor(data: { | ||
id: string, | ||
name: string, | ||
loggedIn: boolean, | ||
api: string, | ||
mgmtCluster: any, | ||
}, ctx: any) { | ||
super(data, ctx); | ||
this.id = data.id; | ||
this.name = data.name; | ||
this.api = data.api; | ||
this.loggedIn = data.loggedIn; | ||
this.mgmtCluster = data.mgmtCluster; | ||
} | ||
|
||
get availableActions() { | ||
return [ | ||
{ | ||
action: 'logOut', | ||
enabled: this.loggedIn, | ||
icon: 'icon icon-fw icon-chevron-right', | ||
label: this.t('nav.userMenu.logOut'), | ||
disabled: false, | ||
}, | ||
]; | ||
} | ||
|
||
get infoUrl() { | ||
return this.api + EpinioInfoPath; | ||
} | ||
|
||
async logOut() { | ||
try { | ||
await epinioAuth.logout(this.createAuthConfig(EpinioAuthTypes.AGNOSTIC)); | ||
|
||
this.loggedIn = false; | ||
} catch (err) { | ||
console.error(`Failed to log out: ${ err }`);// eslint-disable-line no-console | ||
|
||
this.metadata = { | ||
state: { | ||
transitioning: false, | ||
error: true, | ||
message: 'Failed to log out' | ||
} | ||
}; | ||
} | ||
} | ||
|
||
createAuthConfig(type: EpinioAuthTypes, localConfig?: EpinioAuthLocalConfig): EpinioAuthConfig { | ||
const config: EpinioAuthConfig = { | ||
type, | ||
epinioUrl: this.api, | ||
dexConfig: { | ||
dashboardUrl: window.origin, | ||
dexUrl: this.api.replace('epinio', 'auth') | ||
}, | ||
localConfig | ||
}; | ||
|
||
return config; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is there a specific reason to define
cluster
as computed value ?There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Just for readability. This makes it clearer that it's a cluster, instead of an odd first entry in an array