Skip to content

Firefly III: a personal finances manager

Push new oAuth features.

James Coled42012afdda8
diff --git a/app/Http/Controllers/Profile/OAuthController.php b/app/Http/Controllers/Profile/OAuthController.php
index 774d7e11b2..2d8e9a511f 100644
--- a/app/Http/Controllers/Profile/OAuthController.php
+++ b/app/Http/Controllers/Profile/OAuthController.php
@@ -30,6 +30,7 @@ use Illuminate\Http\Response;
use Illuminate\Support\Facades\Date;
use Illuminate\Support\Facades\DB;
use Illuminate\Support\Facades\Log;
+use Laravel\Passport\Client;
use Laravel\Passport\ClientRepository;
use Laravel\Passport\Token;
use Laravel\Passport\TokenRepository;
@@ -38,7 +39,7 @@ class OAuthController extends Controller
{
protected bool $internalAuth;
- public function __construct(protected TokenRepository $tokenRepository,protected ValidationFactory $validation)
+ public function __construct(protected ClientRepository $clients, protected TokenRepository $tokenRepository, protected ValidationFactory $validation)
{
parent::__construct();
@@ -64,17 +65,93 @@ class OAuthController extends Controller
$repository = app(ClientRepository::class);
$repository->createPersonalAccessGrantClient('Firefly III Personal Access Grant Client', null);
}
-
- return view('profile.oauth.index');
+ $link = route('index');
+ return view('profile.oauth.index', compact('link'));
}
public function listClients(): JsonResponse
{
// Retrieving all the OAuth app clients that belong to the user...
- $clients = auth()->user()->oauthApps()->get();
+ $clients = auth()->user()->oauthApps()->where('revoked', false)->get();
return response()->json($clients);
}
+ public function storeClient(Request $request): JsonResponse
+ {
+
+ $this->validation->make($request->all(), [
+ 'name' => ['required', 'string', 'max:255'],
+ 'redirect_uris' => ['required', 'url'],
+ 'confidential' => 'boolean',
+ ])->validate();
+
+ // Creating an OAuth app client that belongs to the given user...
+ $client = app(ClientRepository::class)->createAuthorizationCodeGrantClient(
+ name : $request->input('name'),
+ redirectUris: [$request->input('redirect_uris')],
+ confidential: $request->input('confidential'),
+ user : auth()->user()
+ );
+ $arr = $client->toArray();
+ $arr['plainSecret'] = $client->plainSecret;
+ return response()->json($arr);
+ }
+
+ public function regenerateClientSecret(Request $request, string $clientId): JsonResponse | Response | Client
+ {
+
+
+ $client = auth()->user()->oauthApps()->where('revoked', false)->find($clientId);
+ if (!$client) {
+ return new Response('', 404);
+ }
+ //$client->
+ $this->clients->regenerateSecret($client);
+ $arr = $client->toArray();
+ $arr['plainSecret'] = $client->plainSecret;
+ return response()->json($arr);
+
+ }
+
+ public function updateClient(Request $request, string $clientId): Response | Client
+ {
+ $client = auth()->user()->oauthApps()->where('revoked', false)->find($clientId);
+
+ if (!$client) {
+ return new Response('', 404);
+ }
+
+ $this->validation->make($request->all(), [
+ 'name' => ['required', 'string', 'max:255'],
+ 'redirect_uris' => ['required', 'url'],
+ ])->validate();
+
+ $this->clients->update(
+ $client, $request->input('name'), explode(',', $request->input('redirect_uris'))
+ ); // FIXME replace
+
+ return $client;
+ }
+
+ public function destroyClient(Request $request, string $clientId): Response
+ {
+ /** @var Client $client */
+ $client = auth()->user()->oauthApps()->where('revoked', false)->find($clientId);
+
+ if (!$client) {
+ return new Response('', 404);
+ }
+
+ $client->tokens()->with('refreshToken')->each(function (Token $token): void {
+ $token->refreshToken?->revoke();
+ $token->revoke();
+ });
+
+ $client->forceFill(['revoked' => true])->save();
+
+ return new Response('', Response::HTTP_NO_CONTENT);
+ }
+
public function storePersonalAccessToken(Request $request): JsonResponse
{
$this->validation->make($request->all(), [
@@ -85,6 +162,7 @@ class OAuthController extends Controller
public function destroyPersonalAccessToken(Request $request, string $tokenId): Response
{
+// auth()->user()->fin
$token = $this->tokenRepository->findForUser(
$tokenId, $request->user()
);
diff --git a/resources/assets/v1/src/components/passport/Clients.vue b/resources/assets/v1/src/components/passport/Clients.vue
index 17e8a776e5..ddb4fbf729 100644
--- a/resources/assets/v1/src/components/passport/Clients.vue
+++ b/resources/assets/v1/src/components/passport/Clients.vue
@@ -20,427 +20,463 @@
<style scoped>
.action-link {
- cursor: pointer;
+ cursor: pointer;
}
</style>
<template>
- <div>
- <div class="box box-default">
- <div class="box-header with-border">
- <h3 class="box-title">
- {{ $t('firefly.profile_oauth_clients') }}
- </h3>
- <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>
- {{ $t('firefly.profile_oauth_clients_explain') }}
- </p>
- <p>
- {{ $t('firefly.profile_oauth_clients_external_auth') }}
- </p>
- <p v-if="clients.length === 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>
- </div>
- <div class="box-footer">
- <a class="btn btn-default pull-right" tabindex="-1" @click="showCreateClientForm">
- {{ $t('firefly.profile_oauth_create_new_client') }}
- </a>
- </div>
- </div>
-
- <!-- 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>
-
- <button aria-hidden="true" class="close" data-dismiss="modal" type="button">&times;</button>
- </div>
-
- <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>
+ <div class="box box-default">
+ <div class="box-header with-border">
+ <h3 class="box-title">
+ {{ $t('firefly.profile_oauth_clients') }}
+ </h3>
+ <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>
+ {{ $t('firefly.profile_oauth_clients_explain') }}
+ </p>
+ <p>
+ {{ $t('firefly.profile_oauth_clients_external_auth') }}
+ </p>
+ <p v-if="clients.length === 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 class="width-30" scope="col">{{ $t('firefly.profile_oauth_client_id') }}</th>
+ <th class="width-30" scope="col">{{ $t('firefly.name') }}</th>
+ <th class="width-40" scope="col" style="text-align:right">{{ $t('form.buttons') }}</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;text-align:right">
+ <div class="btn-group">
+ <a :title="$t('firefly.regenerate_secret')" class="btn btn-default btn-sm" @click="regenerateSecret(client)">
+ <em :title="$t('firefly.regenerate_secret')" class="fa fa-retweet"></em>
+ {{ $t('firefly.regenerate_secret') }}
+ </a>
+ <a class="btn btn-sm btn-default" :title="$t('firefly.edit')" tabindex="-1" @click="edit(client)">
+ <em :title="$t('firefly.edit')" class="fa fa-pencil"></em>
+ {{ $t('firefly.edit') }}
+ </a>
+ <a :title="$t('firefly.delete')" class="btn btn-sm btn-danger" @click="destroy(client)">
+ <em :title="$t('firefly.delete')" class="fa fa-trash"></em>
+ {{ $t('firefly.delete') }}
+ </a>
+ </div>
+ </td>
+ </tr>
+ </tbody>
+ </table>
+ </div>
+ <div class="box-footer">
+ <a class="btn btn-default pull-right" tabindex="-1" @click="showCreateClientForm">
+ {{ $t('firefly.profile_oauth_create_new_client') }}
+ </a>
+ </div>
+ </div>
- <!-- Create Client Form -->
- <form role="form" aria-label="form">
- <!-- Name -->
- <div class="form-group row">
- <label class="col-md-3 col-form-label">{{ $t('firefly.name') }}</label>
-
- <div class="col-md-9">
- <input id="create-client-name" v-model="createForm.name" class="form-control" spellcheck="false"
- type="text" @keyup.enter="store">
-
- <span class="form-text text-muted">
+ <!-- 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>
+
+ <button aria-hidden="true" class="close" data-dismiss="modal" type="button">&times;</button>
+ </div>
+
+ <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" aria-label="form">
+ <!-- Name -->
+ <div class="form-group row">
+ <label class="col-md-3 col-form-label">{{ $t('firefly.name') }}</label>
+
+ <div class="col-md-9">
+ <input id="create-client-name" v-model="createForm.name" class="form-control"
+ spellcheck="false"
+ type="text" @keyup.enter="store">
+
+ <span class="form-text text-muted">
{{ $t('firefly.profile_oauth_name_help') }}
</span>
- </div>
- </div>
+ </div>
+ </div>
- <!-- Redirect URL -->
- <div class="form-group row">
- <label class="col-md-3 col-form-label">{{ $t('firefly.profile_oauth_redirect_url') }}</label>
+ <!-- Redirect URIs -->
+ <div class="form-group row">
+ <label class="col-md-3 col-form-label">{{
+ $t('firefly.profile_oauth_redirect_url')
+ }}</label>
- <div class="col-md-9">
- <input v-model="createForm.redirect" class="form-control" name="redirect" spellcheck="false"
- type="text" @keyup.enter="store">
+ <div class="col-md-9">
+ <input v-model="createForm.redirect_uris" class="form-control" name="redirect_uris"
+ spellcheck="false"
+ type="text" @keyup.enter="store">
- <span class="form-text text-muted">
+ <span class="form-text text-muted">
{{ $t('firefly.profile_oauth_redirect_url_help') }}
</span>
- </div>
- </div>
-
- <!-- Confidential -->
- <div class="form-group row">
- <label class="col-md-3 col-form-label">{{ $t('firefly.profile_oauth_confidential') }}</label>
-
- <div class="col-md-9">
- <div class="checkbox">
- <label>
- <input v-model="createForm.confidential" type="checkbox">
- </label>
- </div>
-
- <span class="form-text text-muted">
+ </div>
+ </div>
+
+ <!-- Confidential -->
+ <div class="form-group row">
+ <label class="col-md-3 col-form-label">{{
+ $t('firefly.profile_oauth_confidential')
+ }}</label>
+
+ <div class="col-md-9">
+ <div class="checkbox">
+ <label>
+ <input v-model="createForm.confidential" type="checkbox">
+ </label>
+ </div>
+
+ <span class="form-text text-muted">
{{ $t('firefly.profile_oauth_confidential_help') }}
</span>
+ </div>
+ </div>
+ </form>
+ </div>
+
+ <!-- Modal Actions -->
+ <div class="modal-footer">
+ <button class="btn btn-secondary" data-dismiss="modal" type="button">{{
+ $t('firefly.close')
+ }}
+ </button>
+
+ <button class="btn btn-primary" type="button" @click="store">
+ {{ $t('firefly.profile_create') }}
+ </button>
+ </div>
</div>
- </div>
- </form>
- </div>
-
- <!-- Modal Actions -->
- <div class="modal-footer">
- <button class="btn btn-secondary" data-dismiss="modal" type="button">{{ $t('firefly.close') }}</button>
-
- <button class="btn btn-primary" type="button" @click="store">
- {{ $t('firefly.profile_create') }}
- </button>
- </div>
- </div>
- </div>
- </div>
-
- <!-- 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>
-
- <button aria-hidden="true" class="close" data-dismiss="modal" type="button">&times;</button>
- </div>
-
- <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>
+ </div>
- <!-- Edit Client Form -->
- <form role="form" aria-label="form">
- <!-- Name -->
- <div class="form-group row">
- <label class="col-md-3 col-form-label">{{ $t('firefly.name') }}</label>
-
- <div class="col-md-9">
- <input id="edit-client-name" v-model="editForm.name" class="form-control" spellcheck="false"
- type="text" @keyup.enter="update">
-
- <span class="form-text text-muted">
+ <!-- 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>
+
+ <button aria-hidden="true" class="close" data-dismiss="modal" type="button">&times;</button>
+ </div>
+
+ <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>
+
+ <!-- Edit Client Form -->
+ <form role="form" aria-label="form">
+ <!-- Name -->
+ <div class="form-group row">
+ <label class="col-md-3 col-form-label">{{ $t('firefly.name') }}</label>
+
+ <div class="col-md-9">
+ <input id="edit-client-name" v-model="editForm.name" class="form-control"
+ spellcheck="false"
+ type="text" @keyup.enter="update">
+
+ <span class="form-text text-muted">
{{ $t('firefly.profile_oauth_name_help') }}
</span>
- </div>
- </div>
+ </div>
+ </div>
- <!-- Redirect URL -->
- <div class="form-group row">
- <label class="col-md-3 col-form-label">{{ $t('firefly.profile_oauth_redirect_url') }}</label>
+ <!-- Redirect URL -->
+ <div class="form-group row">
+ <label class="col-md-3 col-form-label">{{
+ $t('firefly.profile_oauth_redirect_url')
+ }}</label>
- <div class="col-md-9">
- <input v-model="editForm.redirect" class="form-control" name="redirect" spellcheck="false"
- type="text" @keyup.enter="update">
+ <div class="col-md-9">
+ <input v-model="editForm.redirect_uris" class="form-control" name="redirect_uris"
+ spellcheck="false"
+ type="text" @keyup.enter="update">
- <span class="form-text text-muted">
+ <span class="form-text text-muted">
{{ $t('firefly.profile_oauth_redirect_url_help') }}
</span>
+ </div>
+ </div>
+ </form>
+ </div>
+
+ <!-- Modal Actions -->
+ <div class="modal-footer">
+ <button class="btn btn-secondary" data-dismiss="modal" type="button">{{
+ $t('firefly.close')
+ }}
+ </button>
+
+ <button class="btn btn-primary" type="button" @click="update">
+ {{ $t('firefly.profile_save_changes') }}
+ </button>
+ </div>
</div>
- </div>
- </form>
- </div>
-
- <!-- Modal Actions -->
- <div class="modal-footer">
- <button class="btn btn-secondary" data-dismiss="modal" type="button">{{ $t('firefly.close') }}</button>
-
- <button class="btn btn-primary" type="button" @click="update">
- {{ $t('firefly.profile_save_changes') }}
- </button>
- </div>
+ </div>
</div>
- </div>
- </div>
- <!-- 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>
-
- <button aria-hidden="true" class="close" data-dismiss="modal" type="button">&times;</button>
- </div>
-
- <div class="modal-body">
- <p>
- {{ $t('firefly.profile_oauth_client_secret_expl') }}
- </p>
-
- <input v-model="clientSecret" class="form-control" type="text" spellcheck="false">
- </div>
-
- <!-- Modal Actions -->
- <div class="modal-footer">
- <button class="btn btn-secondary" data-dismiss="modal" type="button">{{ $t('firefly.close') }}</button>
- </div>
+ <!-- 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>
+
+ <button aria-hidden="true" class="close" data-dismiss="modal" type="button">&times;</button>
+ </div>
+
+ <div class="modal-body">
+ <p>
+ {{ $t('firefly.profile_oauth_client_secret_expl') }}
+ </p>
+ <input id="secret_box" v-model="clientSecret" class="form-control" type="text" spellcheck="false">
+ </div>
+
+ <!-- Modal Actions -->
+ <div class="modal-footer">
+ <button class="btn btn-secondary" data-dismiss="modal" type="button">{{
+ $t('firefly.close')
+ }}
+ </button>
+ </div>
+ </div>
+ </div>
</div>
- </div>
</div>
- </div>
</template>
<script>
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() {
- axios.get('./oauth/clients')
- .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.
+ /*
+ * The component's data.
*/
- store() {
- this.persistClient(
- 'post',
- './oauth/clients',
- this.createForm,
- '#modal-create-client'
- );
+ data() {
+ return {
+ clients: [],
+
+ clientSecret: null,
+
+ createForm: {
+ errors: [],
+ name: '',
+ redirect_uris: '',
+ confidential: true
+ },
+
+ editForm: {
+ errors: [],
+ name: '',
+ redirect_uris: ''
+ }
+ };
},
/**
- * Edit the given client.
+ * Prepare the component (Vue 1.x).
*/
- edit(client) {
- this.editForm.id = client.id;
- this.editForm.name = client.name;
- this.editForm.redirect = client.redirect;
-
- $('#modal-edit-client').modal('show');
+ ready() {
+ this.prepareComponent();
},
/**
- * Update the client being edited.
+ * Prepare the component (Vue 2.x).
*/
- update() {
- this.persistClient(
- 'put',
- './oauth/clients/' + this.editForm.id,
- this.editForm,
- '#modal-edit-client'
- );
+ mounted() {
+ this.prepareComponent();
},
- /**
- * Persist the client to storage using the given form.
- */
- persistClient(method, uri, form, modal) {
- form.errors = [];
-
- axios[method](uri, form)
- .then(response => {
+ methods: {
+ /**
+ * Prepare the component.
+ */
+ prepareComponent() {
this.getClients();
- form.name = '';
- form.redirect = '';
+ $('#modal-create-client').on('shown.bs.modal', () => {
+ $('#create-client-name').focus();
+ });
+
+ $('#modal-edit-client').on('shown.bs.modal', () => {
+ $('#edit-client-name').focus();
+ });
+ const textBox = document.getElementById("secret_box");
+ textBox.onfocus = function () {
+ textBox.select();
+
+ // Work around Chrome's little problem
+ textBox.onmouseup = function () {
+ // Prevent further mouseup intervention
+ textBox.onmouseup = null;
+ return false;
+ };
+ };
+ },
+
+ /**
+ * Get all of the OAuth clients for the user.
+ */
+ getClients() {
+ axios.get('./oauth/clients')
+ .then(response => {
+ console.log(response.data);
+ 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',
+ './oauth/clients',
+ this.createForm,
+ '#modal-create-client'
+ );
+ },
+
+ /**
+ * Edit the given client.
+ */
+ edit(client) {
+ this.editForm.id = client.id;
+ this.editForm.name = client.name;
+ this.editForm.redirect_uris = client.redirect_uris.join(',');
+
+ $('#modal-edit-client').modal('show');
+ },
+
+ /**
+ * Update the client being edited.
+ */
+ update() {
+ this.persistClient(
+ 'put',
+ './oauth/clients/' + this.editForm.id,
+ this.editForm,
+ '#modal-edit-client'
+ );
+ },
+
+ /**
+ * Persist the client to storage using the given form.
+ */
+ persistClient(method, uri, form, modal) {
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.'];
- }
- });
- },
-
- /**
- * Show the given client secret to the user.
- */
- showClientSecret(clientSecret) {
- this.clientSecret = clientSecret;
-
- $('#modal-client-secret').modal('show');
- },
-
- /**
- * Destroy the given client.
- */
- destroy(client) {
- axios.delete('./oauth/clients/' + client.id)
- .then(response => {
- this.getClients();
- });
+ axios[method](uri, form)
+ .then(response => {
+ this.getClients();
+
+ form.name = '';
+ form.redirect_uris = '';
+ 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.'];
+ }
+ });
+ },
+
+ /**
+ * Show the given client secret to the user.
+ */
+ showClientSecret(clientSecret) {
+ this.clientSecret = clientSecret;
+
+ $('#modal-client-secret').modal('show');
+ },
+ regenerateSecret(client) {
+ axios.post('./oauth/clients/regenerate/' + client.id)
+ .then(response => {
+ this.clientSecret = response.data.plainSecret;
+
+ $('#modal-client-secret').modal('show');
+ });
+
+ },
+
+ /**
+ * Destroy the given client.
+ */
+ destroy(client) {
+ axios.delete('./oauth/clients/' + client.id)
+ .then(response => {
+ this.getClients();
+ });
+ }
}
- }
}
</script>
diff --git a/resources/assets/v1/src/components/passport/PersonalAccessTokens.vue b/resources/assets/v1/src/components/passport/PersonalAccessTokens.vue
index 8dd9a9b1c9..781d4280ad 100644
--- a/resources/assets/v1/src/components/passport/PersonalAccessTokens.vue
+++ b/resources/assets/v1/src/components/passport/PersonalAccessTokens.vue
@@ -229,7 +229,7 @@ export default {
*/
prepareComponent() {
this.getTokens();
- this.getScopes();
+ // this.getScopes();
$('#modal-create-token').on('shown.bs.modal', () => {
$('#create-token-name').focus();
diff --git a/resources/assets/v1/src/components/profile/ProfileOptions.vue b/resources/assets/v1/src/components/profile/ProfileOptions.vue
index 4f8ad9ada7..892faf7ea4 100644
--- a/resources/assets/v1/src/components/profile/ProfileOptions.vue
+++ b/resources/assets/v1/src/components/profile/ProfileOptions.vue
@@ -25,11 +25,6 @@
<passport-clients></passport-clients>
</div>
</div>
- <div class="row">
- <div class="col-lg-12">
- <passport-authorized-clients></passport-authorized-clients>
- </div>
- </div>
<div class="row">
<div class="col-lg-12">
<passport-personal-access-tokens></passport-personal-access-tokens>
diff --git a/resources/lang/en_US/firefly.php b/resources/lang/en_US/firefly.php
index b9f19ed373..319c014b74 100644
--- a/resources/lang/en_US/firefly.php
+++ b/resources/lang/en_US/firefly.php
@@ -1639,6 +1639,8 @@ return [
'delete_local_info_only' => "Because Firefly III isn't responsible for user management or authentication handling, this function will only delete local Firefly III information.",
'oauth' => 'OAuth',
'oauth_tokens' => 'Remote access and tokens',
+ 'oauth_tokens_explain' => 'This installation of Firefly III can be reached at <code>:link</code>. This applies to you of course, but also to web applications, AI-agents and other remote programs. However, this access is only possible with the use of Personal Access Tokens or OAuth Clients. Both can be managed on this page. Beware that contrary to previous versions, Firefly III will no longer show you the client secret more than once.',
+ 'regenerate_secret' => 'Regenerate secret',
'profile_oauth_clients' => 'OAuth Clients and Applications',
'explain_pats' => 'Personal Access Tokens are long lived (with a maximum of 1 year) keys that allow direct and unlimited access to your Firefly III data. Tools like the Firefly III Data Importer and the Firefly III integration in Home Assistant use such tokens to connect to Firefly III and do their thing. When you create a token, it is only visible once. The token is also very long.',
'profile_oauth_no_clients' => 'You have not created any OAuth clients or applications.',
@@ -1662,8 +1664,8 @@ return [
'profile_oauth_client_secret_expl' => 'Here is your new client secret. This is the only time it will be shown so don\'t lose it! You may now use this secret to make API requests.',
'profile_personal_access_tokens' => 'Personal Access Tokens',
'profile_personal_access_token' => 'Personal Access Token',
- 'profile_oauth_confidential' => 'Confidential',
- 'profile_oauth_confidential_help' => 'Require the client to authenticate with a secret. Confidential clients can hold credentials in a secure way without exposing them to unauthorized parties. Public applications, such as native desktop or JavaScript SPA applications, are unable to hold secrets securely.',
+ 'profile_oauth_confidential' => 'Keep a secret?',
+ 'profile_oauth_confidential_help' => 'Can the application you\'re using this for keep a secret? The Firefly III Data Importer CANNOT keep a secret, so UNCHECK the box. In other cases, it\'s up to you.',
'profile_personal_access_token_explanation' => 'Here is your new personal access token. This is the only time it will be shown so don\'t lose it! You may now use this token to make API requests.',
'profile_no_personal_access_token' => 'You have not created any personal access tokens.',
'profile_create_new_token' => 'Create new token',
diff --git a/resources/views/profile/index.twig b/resources/views/profile/index.twig
index 087445222c..a8e8c93379 100644
--- a/resources/views/profile/index.twig
+++ b/resources/views/profile/index.twig
@@ -19,17 +19,6 @@
<li role="presentation">
<a href="#cmd" aria-controls="profile" role="tab" data-toggle="tab">{{ 'command_line_token'|_ }}</a>
</li>
- <li role="presentation">
- <a href="#oauth" aria-controls="messages" role="tab" data-toggle="tab">{{ 'oauth'|_ }}</a>
- </li>
- {#
- {% if true == isInternalAuth %}
- <li role="presentation">
- <a href="#mfa" aria-controls="settings" role="tab"
- data-toggle="tab">{{ 'pref_two_factor_auth'|_ }}</a>
- </li>
- {% endif %}
- #}
<li role="presentation">
<a href="#delete" aria-controls="settings" role="tab"
data-toggle="tab">{{ 'delete_stuff_header'|_ }}</a>
@@ -110,52 +99,6 @@
</div>
</div>
- <!-- OAuth -->
- <div role="tabpanel" class="tab-pane" id="oauth">
- <div id="passport_clients"></div>
- </div>
-
- {#
- {% if true == isInternalAuth %}
- <!-- MFA -->
- <div role="tabpanel" class="tab-pane" id="mfa">
- <div class="box box-default">
- <div class="box-body">
- <p class="text-info">{{ 'pref_two_factor_auth_help'|_ }}</p>
- {% if enabled2FA == true %}
- <p class="text-info">
- {{ trans_choice('firefly.pref_two_factor_backup_code_count', mfaBackupCount) }}
- </p>
-
- <div class="btn-group">
- <a class="btn btn-info" href="{{ route('profile.code') }}">
- <span class="fa fa-recycle"></span>
- {{ 'pref_two_factor_auth_reset_code'|_ }}</a>
- </div>
- <form method="post" action="{{ route('profile.delete-code') }}">
- <input type="hidden" name="_token" value="{{ csrf_token() }}"/>
- <input class="btn btn-danger" style="margin-top:20px;" type="submit"
- name="submit" value="{{ 'pref_two_factor_auth_disable_2fa'|_ }}"/>
- </form>
- <form method="post" action="{{ route('profile.new-backup-codes') }}">
- <input type="hidden" name="_token" value="{{ csrf_token() }}"/>
- <input class="btn btn-default" style="margin-top:20px;" type="submit"
- name="submit" value="{{ 'pref_two_factor_new_backup_codes'|_ }}"/>
- </form>
- {% else %}
- <form action="{{ route('profile.enable2FA') }}" method="post">
- <input type="hidden" name="_token" value="{{ csrf_token() }}"/>
- <button type="submit" class="btn btn-info"><span
- class="fa fa-lock"></span> {{ 'pref_enable_two_factor_auth'|_ }}
- </button>
- </form>
- {% endif %}
- </div>
- </div>
- </div>
- {% endif %}
- #}
-
<!-- purge stuff -->
<div role="tabpanel" class="tab-pane" id="delete">
<div class="box box-default">
diff --git a/resources/views/profile/oauth/index.twig b/resources/views/profile/oauth/index.twig
index 981ec0ae87..2067afd1f8 100644
--- a/resources/views/profile/oauth/index.twig
+++ b/resources/views/profile/oauth/index.twig
@@ -9,7 +9,21 @@
<div class="row">
<div class="col-lg-8 col-lg-offset-2 col-md-12 col-sm-12">
- <!-- OAuth -->
+ <div class="row">
+ <div class="col-lg-12">
+ <div class="box box-default">
+ <div class="box-header">
+ <h3 class="box-title">{{ 'oauth_tokens'|_ }}</h3>
+ </div>
+
+ <div class="box-body">
+ <p>
+ {{ trans('firefly.oauth_tokens_explain', {link: link})|raw }}
+ </p>
+ </div>
+ </div>
+ </div>
+ </div>
<div role="tabpanel" class="tab-pane" id="oauth">
<div id="passport_clients"></div>
</div>
diff --git a/routes/web.php b/routes/web.php
index 2d8d39074f..44830e5ea9 100644
--- a/routes/web.php
+++ b/routes/web.php
@@ -48,6 +48,10 @@ Route::group(
// clients:
Route::get('/clients', ['uses' => 'FireflyIII\Http\Controllers\Profile\OAuthController@listClients', 'as' => 'clients.index']);
+ Route::post('/clients', ['uses' => 'FireflyIII\Http\Controllers\Profile\OAuthController@storeClient', 'as' => 'clients.store']);
+ Route::post('/clients/regenerate/{client_id}', ['uses' => 'FireflyIII\Http\Controllers\Profile\OAuthController@regenerateClientSecret', 'as' => 'clients.regen']);
+ Route::put('/clients/{client_id}', ['uses' => 'FireflyIII\Http\Controllers\Profile\OAuthController@updateClient', 'as' => 'clients.update']);
+ Route::delete('/clients/{client_id}', ['uses' => 'FireflyIII\Http\Controllers\Profile\OAuthController@destroyClient', 'as' => 'clients.destroy']);
}
);
@@ -71,10 +75,6 @@ Route::group(
// Route::delete('/authorize', ['uses' => 'DenyAuthorizationController@deny', 'as' => 'authorizations.deny']);
// Route::get('/tokens', ['uses' => 'AuthorizedAccessTokenController@forUser', 'as' => 'tokens.index']);
// Route::delete('/tokens/{token_id}', ['uses' => 'AuthorizedAccessTokenController@destroy', 'as' => 'tokens.destroy']);
-// Route::get('/clients', ['uses' => 'ClientController@forUser', 'as' => 'clients.index']);
-// Route::post('/clients', ['uses' => 'ClientController@store', 'as' => 'clients.store']);
-// Route::put('/clients/{client_id}', ['uses' => 'ClientController@update', 'as' => 'clients.update']);
-// Route::delete('/clients/{client_id}', ['uses' => 'ClientController@destroy', 'as' => 'clients.destroy']);
// Route::get('/scopes', ['uses' => 'ScopeController@all', 'as' => 'scopes.index']);
// Route::get('/personal-access-tokens', ['uses' => 'PersonalAccessTokenController@forUser', 'as' => 'personal.tokens.index']);
// Route::post('/personal-access-tokens', ['uses' => 'PersonalAccessTokenController@store', 'as' => 'personal.tokens.store']);