1
0
mirror of https://github.com/BookStackApp/BookStack.git synced 2025-07-28 17:02:04 +03:00

Built out interfaces & endpoints for API token managment

This commit is contained in:
Dan Brown
2019-12-29 17:03:52 +00:00
parent d336ba6874
commit dccb279c84
14 changed files with 325 additions and 6 deletions

View File

@ -155,8 +155,26 @@ return [
'users_api_tokens' => 'API Tokens',
'users_api_tokens_none' => 'No API tokens have been created for this user',
'users_api_tokens_create' => 'Create Token',
'users_api_tokens_expires' => 'Expires',
// API Tokens
'user_api_token_create' => 'Create API Token',
'user_api_token_name' => 'Name',
'user_api_token_name_desc' => 'Give your token a readable name as a future reminder of its intended purpose.',
'user_api_token_expiry' => 'Expiry Date',
'user_api_token_expiry_desc' => 'Set a date at which this token expires. After this date, requests made using this token will no longer work. Leaving this field blank will set an expiry 100 years into the future.',
'user_api_token_create_secret_message' => 'Immediately after creating this token a "client id"" & "client secret" will be generated and displayed. The client secret will only be shown a single time so be sure to copy the value to somewhere safe and secure before proceeding.',
'user_api_token' => 'API Token',
'user_api_token_client_id' => 'Client ID',
'user_api_token_client_id_desc' => 'This is a non-editable system generated identifier for this token which will need to be provided in API requests.',
'user_api_token_client_secret' => 'Client Secret',
'user_api_token_client_secret_desc' => 'This is a system generated secret for this token which will need to be provided in API requests. This will only be displayed this one time so copy this value to somewhere safe and secure.',
'user_api_token_created' => 'Token Created :timeAgo',
'user_api_token_updated' => 'Token Updated :timeAgo',
'user_api_token_delete' => 'Delete Token',
'user_api_token_delete_warning' => 'This will fully delete this API token with the name \':tokenName\' from the system.',
'user_api_token_delete_confirm' => 'Are you sure you want to delete this API token?',
'user_api_token_delete_success' => 'API token successfully deleted',
//! If editing translations files directly please ignore this in all
//! languages apart from en. Content will be auto-copied from en.

View File

@ -19,6 +19,9 @@
&.disabled, &[disabled] {
background: url(data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAAcAAAAHCAYAAADEUlfTAAAAMUlEQVQIW2NkwAGuXbv2nxGbHEhCS0uLEUMSJgHShCKJLIEiiS4Bl8QmAZbEJQGSBAC62BuJ+tt7zgAAAABJRU5ErkJggg==);
}
&[readonly] {
background-color: #f8f8f8;
}
&:focus {
border-color: var(--color-primary);
outline: 1px solid var(--color-primary);

View File

@ -0,0 +1,9 @@
<input type="date" id="{{ $name }}" name="{{ $name }}"
@if($errors->has($name)) class="text-neg" @endif
placeholder="{{ $placeholder ?? 'YYYY-MM-DD' }}"
@if($autofocus ?? false) autofocus @endif
@if($disabled ?? false) disabled="disabled" @endif
@if(isset($model) || old($name)) value="{{ old($name) ?? $model->$name->format('Y-m-d') ?? ''}}" @endif>
@if($errors->has($name))
<div class="text-neg text-small">{{ $errors->first($name) }}</div>
@endif

View File

@ -3,6 +3,7 @@
@if(isset($placeholder)) placeholder="{{$placeholder}}" @endif
@if($autofocus ?? false) autofocus @endif
@if($disabled ?? false) disabled="disabled" @endif
@if($readonly ?? false) readonly="readonly" @endif
@if(isset($model) || old($name)) value="{{ old($name) ? old($name) : $model->$name}}" @endif>
@if($errors->has($name))
<div class="text-neg text-small">{{ $errors->first($name) }}</div>

View File

@ -0,0 +1,33 @@
@extends('simple-layout')
@section('body')
<div class="container small pt-xl">
<main class="card content-wrap auto-height">
<h1 class="list-heading">{{ trans('settings.user_api_token_create') }}</h1>
<form action="{{ $user->getEditUrl('/create-api-token') }}" method="post">
{!! csrf_field() !!}
<div class="setting-list">
@include('users.api-tokens.form')
<div>
<p class="text-warn italic">
{{ trans('settings.user_api_token_create_secret_message') }}
</p>
</div>
</div>
<div class="form-group text-right">
<a href="{{ $user->getEditUrl('#api_tokens') }}" class="button outline">{{ trans('common.cancel') }}</a>
<button class="button" type="submit">{{ trans('common.save') }}</button>
</div>
</form>
</main>
</div>
@stop

View File

@ -0,0 +1,26 @@
@extends('simple-layout')
@section('body')
<div class="container small pt-xl">
<div class="card content-wrap auto-height">
<h1 class="list-heading">{{ trans('settings.user_api_token_delete') }}</h1>
<p>{{ trans('settings.user_api_token_delete_warning', ['tokenName' => $token->name]) }}</p>
<div class="grid half">
<p class="text-neg"><strong>{{ trans('settings.user_api_token_delete_confirm') }}</strong></p>
<div>
<form action="{{ $user->getEditUrl('/api-tokens/' . $token->id) }}" method="POST" class="text-right">
{!! csrf_field() !!}
{!! method_field('delete') !!}
<a href="{{ $user->getEditUrl('/api-tokens/' . $token->id) }}" class="button outline">{{ trans('common.cancel') }}</a>
<button type="submit" class="button">{{ trans('common.confirm') }}</button>
</form>
</div>
</div>
</div>
</div>
@stop

View File

@ -0,0 +1,66 @@
@extends('simple-layout')
@section('body')
<div class="container small pt-xl">
<main class="card content-wrap auto-height">
<h1 class="list-heading">{{ trans('settings.user_api_token') }}</h1>
<form action="{{ $user->getEditUrl('/api-tokens/' . $token->id) }}" method="post">
{!! method_field('put') !!}
{!! csrf_field() !!}
<div class="setting-list">
<div class="grid half gap-xl v-center">
<div>
<label class="setting-list-label">{{ trans('settings.user_api_token_client_id') }}</label>
<p class="small">{{ trans('settings.user_api_token_client_id_desc') }}</p>
</div>
<div>
@include('form.text', ['name' => 'client_id', 'readonly' => true])
</div>
</div>
@if( $secret )
<div class="grid half gap-xl v-center">
<div>
<label class="setting-list-label">{{ trans('settings.user_api_token_client_secret') }}</label>
<p class="small text-warn">{{ trans('settings.user_api_token_client_secret_desc') }}</p>
</div>
<div>
<input type="text" readonly="readonly" value="{{ $secret }}">
</div>
</div>
@endif
@include('users.api-tokens.form', ['model' => $token])
</div>
<div class="grid half gap-xl v-center">
<div class="text-muted text-small">
<span title="{{ $token->created_at }}">
{{ trans('settings.user_api_token_created', ['timeAgo' => $token->created_at->diffForHumans()]) }}
</span>
<br>
<span title="{{ $token->updated_at }}">
{{ trans('settings.user_api_token_updated', ['timeAgo' => $token->created_at->diffForHumans()]) }}
</span>
</div>
<div class="form-group text-right">
<a href="{{ $user->getEditUrl('#api_tokens') }}" class="button outline">{{ trans('common.back') }}</a>
<a href="{{ $user->getEditUrl('/api-tokens/' . $token->id . '/delete') }}" class="button outline">{{ trans('settings.user_api_token_delete') }}</a>
<button class="button" type="submit">{{ trans('common.save') }}</button>
</div>
</div>
</form>
</main>
</div>
@stop

View File

@ -0,0 +1,21 @@
<div class="grid half gap-xl v-center">
<div>
<label class="setting-list-label">{{ trans('settings.user_api_token_name') }}</label>
<p class="small">{{ trans('settings.user_api_token_name_desc') }}</p>
</div>
<div>
@include('form.text', ['name' => 'name'])
</div>
</div>
<div class="grid half gap-xl v-center">
<div>
<label class="setting-list-label">{{ trans('settings.user_api_token_expiry') }}</label>
<p class="small">{{ trans('settings.user_api_token_expiry_desc') }}</p>
</div>
<div class="text-right">
@include('form.date', ['name' => 'expires_at'])
</div>
</div>

View File

@ -90,7 +90,7 @@
{{-- TODO - Review Control--}}
@if(($currentUser->id === $user->id && userCan('access-api')) || userCan('manage-users'))
<section class="card content-wrap auto-height">
<section class="card content-wrap auto-height" id="api_tokens">
<div class="grid half">
<div><h2 class="list-heading">{{ trans('settings.users_api_tokens') }}</h2></div>
<div class="text-right pt-xs">
@ -100,7 +100,25 @@
</div>
</div>
@if (count($user->apiTokens) > 0)
<table class="table">
<tr>
<th>{{ trans('common.name') }}</th>
<th>{{ trans('settings.users_api_tokens_expires') }}</th>
<th></th>
</tr>
@foreach($user->apiTokens as $token)
<tr>
<td>
{{ $token->name }} <br>
<span class="small text-muted italic">{{ $token->client_id }}</span>
</td>
<td>{{ $token->expires_at->format('Y-m-d') ?? '' }}</td>
<td class="text-right">
<a class="button outline small" href="{{ $user->getEditUrl('/api-tokens/' . $token->id) }}">{{ trans('common.edit') }}</a>
</td>
</tr>
@endforeach
</table>
@else
<p class="text-muted italic py-m">{{ trans('settings.users_api_tokens_none') }}</p>
@endif