2023-03-14 13:18:55 +00:00
|
|
|
/**
|
|
|
|
* Copyright (c) HashiCorp, Inc.
|
|
|
|
* SPDX-License-Identifier: MPL-2.0
|
|
|
|
*/
|
|
|
|
|
2022-01-07 19:08:25 +00:00
|
|
|
import Component from '@glimmer/component';
|
2020-05-11 15:37:11 +00:00
|
|
|
import { inject as service } from '@ember/service';
|
2022-01-07 19:08:25 +00:00
|
|
|
import { get, action } from '@ember/object';
|
2020-05-11 15:37:11 +00:00
|
|
|
import chart from './chart.xstate';
|
|
|
|
|
2022-01-07 19:08:25 +00:00
|
|
|
export default class AuthDialog extends Component {
|
|
|
|
@service('repository/oidc-provider') repo;
|
|
|
|
|
|
|
|
constructor() {
|
|
|
|
super(...arguments);
|
2020-05-11 15:37:11 +00:00
|
|
|
this.chart = chart;
|
2022-01-07 19:08:25 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
@action
|
|
|
|
hasToken() {
|
|
|
|
return typeof this.token.AccessorID !== 'undefined';
|
|
|
|
}
|
|
|
|
|
|
|
|
@action
|
|
|
|
login() {
|
|
|
|
let prev = get(this, 'previousToken.AccessorID');
|
|
|
|
let current = get(this, 'token.AccessorID');
|
|
|
|
if (prev === null) {
|
|
|
|
prev = get(this, 'previousToken.SecretID');
|
|
|
|
}
|
|
|
|
if (current === null) {
|
|
|
|
current = get(this, 'token.SecretID');
|
|
|
|
}
|
|
|
|
let type = 'authorize';
|
|
|
|
if (typeof prev !== 'undefined' && prev !== current) {
|
|
|
|
type = 'use';
|
|
|
|
}
|
|
|
|
this.args.onchange({ data: get(this, 'token'), type: type });
|
|
|
|
}
|
|
|
|
|
|
|
|
@action
|
|
|
|
logout() {
|
|
|
|
if (typeof get(this, 'previousToken.AuthMethod') !== 'undefined') {
|
|
|
|
// we are ok to fire and forget here
|
|
|
|
this.repo.logout(get(this, 'previousToken.SecretID'));
|
|
|
|
}
|
|
|
|
this.previousToken = null;
|
|
|
|
this.args.onchange({ data: null, type: 'logout' });
|
|
|
|
}
|
|
|
|
}
|