2023-03-14 13:18:55 +00:00
|
|
|
/**
|
|
|
|
* Copyright (c) HashiCorp, Inc.
|
2023-08-11 13:12:13 +00:00
|
|
|
* SPDX-License-Identifier: BUSL-1.1
|
2023-03-14 13:18:55 +00:00
|
|
|
*/
|
|
|
|
|
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';
|
|
|
|
}
|
2023-03-20 22:41:47 +00:00
|
|
|
this.args.onchange({ data: this.token, type: type });
|
2022-01-07 19:08:25 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
@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' });
|
|
|
|
}
|
|
|
|
}
|