2019-05-29 14:56:39 -05:00
|
|
|
<!--
|
|
|
|
- Clients.vue
|
2020-01-24 23:08:56 -06:00
|
|
|
- Copyright (c) 2019 james@firefly-iii.org
|
2019-05-29 14:56:39 -05:00
|
|
|
-
|
2019-10-01 23:43:38 -05:00
|
|
|
- This file is part of Firefly III (https://github.com/firefly-iii).
|
2019-05-29 14:56:39 -05:00
|
|
|
-
|
2019-10-01 23:43:38 -05:00
|
|
|
- This program is free software: you can redistribute it and/or modify
|
|
|
|
- it under the terms of the GNU Affero General Public License as
|
|
|
|
- published by the Free Software Foundation, either version 3 of the
|
|
|
|
- License, or (at your option) any later version.
|
2019-05-29 14:56:39 -05:00
|
|
|
-
|
2019-10-01 23:43:38 -05:00
|
|
|
- This program is distributed in the hope that it will be useful,
|
2019-05-29 14:56:39 -05:00
|
|
|
- but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
2019-10-01 23:43:38 -05:00
|
|
|
- GNU Affero General Public License for more details.
|
2019-05-29 14:56:39 -05:00
|
|
|
-
|
2019-10-01 23:43:38 -05:00
|
|
|
- You should have received a copy of the GNU Affero General Public License
|
|
|
|
- along with this program. If not, see <https://www.gnu.org/licenses/>.
|
2019-05-29 14:56:39 -05:00
|
|
|
-->
|
|
|
|
|
2018-01-31 10:55:49 -06:00
|
|
|
<style scoped>
|
2020-08-05 00:15:28 -05:00
|
|
|
.action-link {
|
|
|
|
cursor: pointer;
|
|
|
|
}
|
2018-01-31 10:55:49 -06:00
|
|
|
</style>
|
|
|
|
|
|
|
|
<template>
|
2020-08-05 00:15:28 -05:00
|
|
|
<div>
|
|
|
|
<div class="box box-default">
|
|
|
|
<div class="box-header with-border">
|
|
|
|
<h3 class="box-title">
|
|
|
|
{{ $t('firefly.profile_oauth_clients') }}
|
|
|
|
</h3>
|
2020-10-17 14:41:13 -05:00
|
|
|
<a class="btn btn-default pull-right" tabindex="-1" @click="showCreateClientForm">
|
|
|
|
{{ $t('firefly.profile_oauth_create_new_client') }}
|
|
|
|
</a>
|
|
|
|
</div>
|
|
|
|
<div class="box-body">
|
|
|
|
<!-- Current Clients -->
|
|
|
|
<p v-if="clients.length === 0" class="mb-0">
|
|
|
|
{{ $t('firefly.profile_oauth_no_clients') }}
|
|
|
|
</p>
|
|
|
|
|
|
|
|
<table v-if="clients.length > 0" class="table table-responsive table-borderless mb-0">
|
|
|
|
<caption>{{ $t('firefly.profile_oauth_clients_header') }}</caption>
|
|
|
|
<thead>
|
|
|
|
<tr>
|
|
|
|
<th scope="col">{{ $t('firefly.profile_oauth_client_id') }}</th>
|
|
|
|
<th scope="col">{{ $t('firefly.name') }}</th>
|
|
|
|
<th scope="col">{{ $t('firefly.profile_oauth_client_secret') }}</th>
|
|
|
|
<th scope="col"></th>
|
|
|
|
<th scope="col"></th>
|
|
|
|
</tr>
|
|
|
|
</thead>
|
|
|
|
|
|
|
|
<tbody>
|
|
|
|
<tr v-for="client in clients">
|
|
|
|
<!-- ID -->
|
|
|
|
<td style="vertical-align: middle;">
|
|
|
|
{{ client.id }}
|
|
|
|
</td>
|
|
|
|
|
|
|
|
<!-- Name -->
|
|
|
|
<td style="vertical-align: middle;">
|
|
|
|
{{ client.name }}
|
|
|
|
</td>
|
|
|
|
|
|
|
|
<!-- Secret -->
|
|
|
|
<td style="vertical-align: middle;">
|
|
|
|
<code>{{ client.secret ? client.secret : '-' }}</code>
|
|
|
|
</td>
|
|
|
|
|
|
|
|
<!-- Edit Button -->
|
|
|
|
<td style="vertical-align: middle;">
|
|
|
|
<a class="action-link" tabindex="-1" @click="edit(client)">
|
|
|
|
{{ $t('firefly.edit') }}
|
|
|
|
</a>
|
|
|
|
</td>
|
|
|
|
|
|
|
|
<!-- Delete Button -->
|
|
|
|
<td style="vertical-align: middle;">
|
|
|
|
<a class="action-link text-danger" @click="destroy(client)">
|
|
|
|
{{ $t('firefly.delete') }}
|
|
|
|
</a>
|
|
|
|
</td>
|
|
|
|
</tr>
|
|
|
|
</tbody>
|
|
|
|
</table>
|
2020-08-05 00:15:28 -05:00
|
|
|
</div>
|
|
|
|
<div class="box-footer">
|
2020-10-17 14:41:13 -05:00
|
|
|
<a class="btn btn-default pull-right" tabindex="-1" @click="showCreateClientForm">
|
2020-08-05 00:15:28 -05:00
|
|
|
{{ $t('firefly.profile_oauth_create_new_client') }}
|
|
|
|
</a>
|
|
|
|
</div>
|
2020-10-17 14:41:13 -05:00
|
|
|
</div>
|
2020-08-05 00:15:28 -05:00
|
|
|
|
2020-10-17 14:41:13 -05:00
|
|
|
<!-- Create Client Modal -->
|
|
|
|
<div id="modal-create-client" class="modal fade" role="dialog" tabindex="-1">
|
|
|
|
<div class="modal-dialog">
|
|
|
|
<div class="modal-content">
|
|
|
|
<div class="modal-header">
|
|
|
|
<h4 class="modal-title">
|
|
|
|
{{ $t('firefly.profile_oauth_create_client') }}
|
|
|
|
</h4>
|
2020-08-05 00:15:28 -05:00
|
|
|
|
2020-10-17 14:41:13 -05:00
|
|
|
<button aria-hidden="true" class="close" data-dismiss="modal" type="button">×</button>
|
2020-08-05 00:15:28 -05:00
|
|
|
</div>
|
|
|
|
|
2020-10-17 14:41:13 -05:00
|
|
|
<div class="modal-body">
|
|
|
|
<!-- Form Errors -->
|
|
|
|
<div v-if="createForm.errors.length > 0" class="alert alert-danger">
|
|
|
|
<p class="mb-0"><strong>{{ $t('firefly.profile_whoops') }}</strong> {{
|
|
|
|
$t('firefly.profile_something_wrong')
|
|
|
|
}}</p>
|
|
|
|
<br>
|
|
|
|
<ul>
|
|
|
|
<li v-for="error in createForm.errors">
|
|
|
|
{{ error }}
|
|
|
|
</li>
|
|
|
|
</ul>
|
|
|
|
</div>
|
|
|
|
|
|
|
|
<!-- Create Client Form -->
|
|
|
|
<form role="form">
|
|
|
|
<!-- Name -->
|
|
|
|
<div class="form-group row">
|
|
|
|
<label class="col-md-3 col-form-label">{{ $t('firefly.name') }}</label>
|
2020-08-05 00:15:28 -05:00
|
|
|
|
2020-10-17 14:41:13 -05:00
|
|
|
<div class="col-md-9">
|
|
|
|
<input id="create-client-name" v-model="createForm.name" class="form-control"
|
|
|
|
type="text" @keyup.enter="store">
|
2020-08-05 00:15:28 -05:00
|
|
|
|
2020-10-17 14:41:13 -05:00
|
|
|
<span class="form-text text-muted">
|
2020-08-05 00:15:28 -05:00
|
|
|
{{ $t('firefly.profile_oauth_name_help') }}
|
2018-01-31 10:55:49 -06:00
|
|
|
</span>
|
2020-10-17 14:41:13 -05:00
|
|
|
</div>
|
2020-08-05 00:15:28 -05:00
|
|
|
</div>
|
2018-01-31 10:55:49 -06:00
|
|
|
|
2020-10-17 14:41:13 -05:00
|
|
|
<!-- Redirect URL -->
|
|
|
|
<div class="form-group row">
|
|
|
|
<label class="col-md-3 col-form-label">{{ $t('firefly.profile_oauth_redirect_url') }}</label>
|
2018-01-31 10:55:49 -06:00
|
|
|
|
2020-10-17 14:41:13 -05:00
|
|
|
<div class="col-md-9">
|
|
|
|
<input v-model="createForm.redirect" class="form-control" name="redirect"
|
|
|
|
type="text" @keyup.enter="store">
|
2018-01-31 10:55:49 -06:00
|
|
|
|
2020-10-17 14:41:13 -05:00
|
|
|
<span class="form-text text-muted">
|
2020-08-05 00:15:28 -05:00
|
|
|
{{ $t('firefly.profile_oauth_redirect_url_help') }}
|
2018-01-31 10:55:49 -06:00
|
|
|
</span>
|
2020-10-17 14:41:13 -05:00
|
|
|
</div>
|
2020-08-05 00:15:28 -05:00
|
|
|
</div>
|
|
|
|
|
2020-10-17 14:41:13 -05:00
|
|
|
<!-- Confidential -->
|
|
|
|
<div class="form-group row">
|
|
|
|
<label class="col-md-3 col-form-label">{{ $t('firefly.profile_oauth_confidential') }}</label>
|
2020-08-05 00:15:28 -05:00
|
|
|
|
2020-10-17 14:41:13 -05:00
|
|
|
<div class="col-md-9">
|
|
|
|
<div class="checkbox">
|
|
|
|
<label>
|
|
|
|
<input v-model="createForm.confidential" type="checkbox">
|
|
|
|
</label>
|
|
|
|
</div>
|
2020-08-05 00:15:28 -05:00
|
|
|
|
2020-10-17 14:41:13 -05:00
|
|
|
<span class="form-text text-muted">
|
2020-08-05 00:15:28 -05:00
|
|
|
{{ $t('firefly.profile_oauth_confidential_help') }}
|
|
|
|
</span>
|
2020-10-17 14:41:13 -05:00
|
|
|
</div>
|
2020-08-05 00:15:28 -05:00
|
|
|
</div>
|
2020-10-17 14:41:13 -05:00
|
|
|
</form>
|
|
|
|
</div>
|
2018-01-31 10:55:49 -06:00
|
|
|
|
2020-10-17 14:41:13 -05:00
|
|
|
<!-- Modal Actions -->
|
|
|
|
<div class="modal-footer">
|
|
|
|
<button class="btn btn-secondary" data-dismiss="modal" type="button">{{ $t('firefly.close') }}</button>
|
2018-01-31 10:55:49 -06:00
|
|
|
|
2020-10-17 14:41:13 -05:00
|
|
|
<button class="btn btn-primary" type="button" @click="store">
|
|
|
|
{{ $t('firefly.profile_create') }}
|
|
|
|
</button>
|
|
|
|
</div>
|
2020-08-05 00:15:28 -05:00
|
|
|
</div>
|
|
|
|
</div>
|
|
|
|
</div>
|
|
|
|
|
2020-10-17 14:41:13 -05:00
|
|
|
<!-- Edit Client Modal -->
|
|
|
|
<div id="modal-edit-client" class="modal fade" role="dialog" tabindex="-1">
|
|
|
|
<div class="modal-dialog">
|
|
|
|
<div class="modal-content">
|
|
|
|
<div class="modal-header">
|
|
|
|
<h4 class="modal-title">
|
|
|
|
{{ $t('firefly.profile_oauth_edit_client') }}
|
|
|
|
</h4>
|
2020-08-05 00:15:28 -05:00
|
|
|
|
2020-10-17 14:41:13 -05:00
|
|
|
<button aria-hidden="true" class="close" data-dismiss="modal" type="button">×</button>
|
2020-08-05 00:15:28 -05:00
|
|
|
</div>
|
|
|
|
|
2020-10-17 14:41:13 -05:00
|
|
|
<div class="modal-body">
|
|
|
|
<!-- Form Errors -->
|
|
|
|
<div v-if="editForm.errors.length > 0" class="alert alert-danger">
|
|
|
|
<p class="mb-0"><strong>{{ $t('firefly.profile_whoops') }}</strong> {{
|
|
|
|
$t('firefly.profile_something_wrong')
|
|
|
|
}}</p>
|
|
|
|
<br>
|
|
|
|
<ul>
|
|
|
|
<li v-for="error in editForm.errors">
|
|
|
|
{{ error }}
|
|
|
|
</li>
|
|
|
|
</ul>
|
|
|
|
</div>
|
2020-08-05 00:15:28 -05:00
|
|
|
|
2020-10-17 14:41:13 -05:00
|
|
|
<!-- Edit Client Form -->
|
|
|
|
<form role="form">
|
|
|
|
<!-- Name -->
|
|
|
|
<div class="form-group row">
|
|
|
|
<label class="col-md-3 col-form-label">{{ $t('firefly.name') }}</label>
|
2020-08-05 00:15:28 -05:00
|
|
|
|
2020-10-17 14:41:13 -05:00
|
|
|
<div class="col-md-9">
|
|
|
|
<input id="edit-client-name" v-model="editForm.name" class="form-control"
|
|
|
|
type="text" @keyup.enter="update">
|
|
|
|
|
|
|
|
<span class="form-text text-muted">
|
2020-08-05 00:15:28 -05:00
|
|
|
{{ $t('firefly.profile_oauth_name_help') }}
|
|
|
|
</span>
|
2020-10-17 14:41:13 -05:00
|
|
|
</div>
|
2020-08-05 00:15:28 -05:00
|
|
|
</div>
|
|
|
|
|
2020-10-17 14:41:13 -05:00
|
|
|
<!-- Redirect URL -->
|
|
|
|
<div class="form-group row">
|
|
|
|
<label class="col-md-3 col-form-label">{{ $t('firefly.profile_oauth_redirect_url') }}</label>
|
2018-01-31 10:55:49 -06:00
|
|
|
|
2020-10-17 14:41:13 -05:00
|
|
|
<div class="col-md-9">
|
|
|
|
<input v-model="editForm.redirect" class="form-control" name="redirect"
|
|
|
|
type="text" @keyup.enter="update">
|
2018-01-31 10:55:49 -06:00
|
|
|
|
2020-10-17 14:41:13 -05:00
|
|
|
<span class="form-text text-muted">
|
2020-05-28 23:22:13 -05:00
|
|
|
{{ $t('firefly.profile_oauth_redirect_url_help') }}
|
2018-01-31 10:55:49 -06:00
|
|
|
</span>
|
2020-10-17 14:41:13 -05:00
|
|
|
</div>
|
2020-08-05 00:15:28 -05:00
|
|
|
</div>
|
2020-10-17 14:41:13 -05:00
|
|
|
</form>
|
|
|
|
</div>
|
2020-08-05 00:15:28 -05:00
|
|
|
|
2020-10-17 14:41:13 -05:00
|
|
|
<!-- Modal Actions -->
|
|
|
|
<div class="modal-footer">
|
|
|
|
<button class="btn btn-secondary" data-dismiss="modal" type="button">{{ $t('firefly.close') }}</button>
|
2020-08-05 00:15:28 -05:00
|
|
|
|
2020-10-17 14:41:13 -05:00
|
|
|
<button class="btn btn-primary" type="button" @click="update">
|
|
|
|
{{ $t('firefly.profile_save_changes') }}
|
|
|
|
</button>
|
|
|
|
</div>
|
2018-01-31 10:55:49 -06:00
|
|
|
</div>
|
2020-08-05 00:15:28 -05:00
|
|
|
</div>
|
2018-01-31 10:55:49 -06:00
|
|
|
</div>
|
2020-08-05 00:15:28 -05:00
|
|
|
|
2020-10-17 14:41:13 -05:00
|
|
|
<!-- Client Secret Modal -->
|
|
|
|
<div id="modal-client-secret" class="modal fade" role="dialog" tabindex="-1">
|
|
|
|
<div class="modal-dialog">
|
|
|
|
<div class="modal-content">
|
|
|
|
<div class="modal-header">
|
|
|
|
<h4 class="modal-title">
|
|
|
|
{{ $t('firefly.profile_oauth_client_secret_title') }}
|
|
|
|
</h4>
|
2020-08-05 00:15:28 -05:00
|
|
|
|
2020-10-17 14:41:13 -05:00
|
|
|
<button aria-hidden="true" class="close" data-dismiss="modal" type="button">×</button>
|
|
|
|
</div>
|
2020-08-05 00:15:28 -05:00
|
|
|
|
2020-10-17 14:41:13 -05:00
|
|
|
<div class="modal-body">
|
|
|
|
<p>
|
|
|
|
{{ $t('firefly.profile_oauth_client_secret_expl') }}
|
|
|
|
</p>
|
2020-08-05 00:15:28 -05:00
|
|
|
|
2020-10-17 14:41:13 -05:00
|
|
|
<input v-model="clientSecret" class="form-control" type="text">
|
|
|
|
</div>
|
2020-08-05 00:15:28 -05:00
|
|
|
|
2020-10-17 14:41:13 -05:00
|
|
|
<!-- Modal Actions -->
|
|
|
|
<div class="modal-footer">
|
|
|
|
<button class="btn btn-secondary" data-dismiss="modal" type="button">{{ $t('firefly.close') }}</button>
|
|
|
|
</div>
|
2020-08-05 00:15:28 -05:00
|
|
|
</div>
|
|
|
|
</div>
|
|
|
|
</div>
|
|
|
|
</div>
|
2018-01-31 10:55:49 -06:00
|
|
|
</template>
|
|
|
|
|
|
|
|
<script>
|
2020-08-05 00:15:28 -05:00
|
|
|
export default {
|
|
|
|
/*
|
|
|
|
* The component's data.
|
|
|
|
*/
|
|
|
|
data() {
|
|
|
|
return {
|
|
|
|
clients: [],
|
|
|
|
|
|
|
|
clientSecret: null,
|
|
|
|
|
|
|
|
createForm: {
|
|
|
|
errors: [],
|
|
|
|
name: '',
|
|
|
|
redirect: '',
|
|
|
|
confidential: true
|
|
|
|
},
|
|
|
|
|
|
|
|
editForm: {
|
|
|
|
errors: [],
|
|
|
|
name: '',
|
|
|
|
redirect: ''
|
|
|
|
}
|
|
|
|
};
|
|
|
|
},
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Prepare the component (Vue 1.x).
|
|
|
|
*/
|
|
|
|
ready() {
|
|
|
|
this.prepareComponent();
|
|
|
|
},
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Prepare the component (Vue 2.x).
|
|
|
|
*/
|
|
|
|
mounted() {
|
|
|
|
this.prepareComponent();
|
|
|
|
},
|
|
|
|
|
|
|
|
methods: {
|
|
|
|
/**
|
|
|
|
* Prepare the component.
|
|
|
|
*/
|
|
|
|
prepareComponent() {
|
|
|
|
this.getClients();
|
|
|
|
|
|
|
|
$('#modal-create-client').on('shown.bs.modal', () => {
|
|
|
|
$('#create-client-name').focus();
|
|
|
|
});
|
|
|
|
|
|
|
|
$('#modal-edit-client').on('shown.bs.modal', () => {
|
|
|
|
$('#edit-client-name').focus();
|
|
|
|
});
|
|
|
|
},
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Get all of the OAuth clients for the user.
|
|
|
|
*/
|
|
|
|
getClients() {
|
2020-10-12 23:51:44 -05:00
|
|
|
axios.get('./oauth/clients')
|
2020-08-05 00:15:28 -05:00
|
|
|
.then(response => {
|
|
|
|
this.clients = response.data;
|
|
|
|
});
|
|
|
|
},
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Show the form for creating new clients.
|
|
|
|
*/
|
|
|
|
showCreateClientForm() {
|
|
|
|
$('#modal-create-client').modal('show');
|
|
|
|
},
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Create a new OAuth client for the user.
|
|
|
|
*/
|
|
|
|
store() {
|
|
|
|
this.persistClient(
|
|
|
|
'post',
|
2020-10-12 23:51:44 -05:00
|
|
|
'./oauth/clients',
|
2020-08-05 00:15:28 -05:00
|
|
|
this.createForm,
|
|
|
|
'#modal-create-client'
|
|
|
|
);
|
|
|
|
},
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Edit the given client.
|
|
|
|
*/
|
|
|
|
edit(client) {
|
|
|
|
this.editForm.id = client.id;
|
|
|
|
this.editForm.name = client.name;
|
|
|
|
this.editForm.redirect = client.redirect;
|
|
|
|
|
|
|
|
$('#modal-edit-client').modal('show');
|
|
|
|
},
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Update the client being edited.
|
|
|
|
*/
|
|
|
|
update() {
|
|
|
|
this.persistClient(
|
|
|
|
'put',
|
2020-10-12 23:51:44 -05:00
|
|
|
'./oauth/clients/' + this.editForm.id,
|
2020-08-05 00:15:28 -05:00
|
|
|
this.editForm,
|
|
|
|
'#modal-edit-client'
|
|
|
|
);
|
|
|
|
},
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Persist the client to storage using the given form.
|
|
|
|
*/
|
|
|
|
persistClient(method, uri, form, modal) {
|
|
|
|
form.errors = [];
|
|
|
|
|
|
|
|
axios[method](uri, form)
|
|
|
|
.then(response => {
|
|
|
|
this.getClients();
|
|
|
|
|
|
|
|
form.name = '';
|
|
|
|
form.redirect = '';
|
|
|
|
form.errors = [];
|
|
|
|
|
|
|
|
$(modal).modal('hide');
|
|
|
|
|
|
|
|
if (response.data.plainSecret) {
|
|
|
|
this.showClientSecret(response.data.plainSecret);
|
|
|
|
}
|
|
|
|
})
|
|
|
|
.catch(error => {
|
|
|
|
if (typeof error.response.data === 'object') {
|
|
|
|
form.errors = _.flatten(_.toArray(error.response.data.errors));
|
|
|
|
} else {
|
|
|
|
form.errors = ['Something went wrong. Please try again.'];
|
2018-01-31 10:55:49 -06:00
|
|
|
}
|
2020-08-05 00:15:28 -05:00
|
|
|
});
|
|
|
|
},
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Show the given client secret to the user.
|
|
|
|
*/
|
|
|
|
showClientSecret(clientSecret) {
|
|
|
|
this.clientSecret = clientSecret;
|
|
|
|
|
|
|
|
$('#modal-client-secret').modal('show');
|
|
|
|
},
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Destroy the given client.
|
|
|
|
*/
|
|
|
|
destroy(client) {
|
2020-10-12 23:51:44 -05:00
|
|
|
axios.delete('./oauth/clients/' + client.id)
|
2020-08-05 00:15:28 -05:00
|
|
|
.then(response => {
|
|
|
|
this.getClients();
|
|
|
|
});
|
2018-01-31 10:55:49 -06:00
|
|
|
}
|
2020-08-05 00:15:28 -05:00
|
|
|
}
|
|
|
|
}
|
2018-01-31 10:55:49 -06:00
|
|
|
</script>
|