|
|
|
|
@ -21,30 +21,56 @@
|
|
|
|
|
</div>
|
|
|
|
|
|
|
|
|
|
<div class="card-body">
|
|
|
|
|
<!-- No Tokens Notice -->
|
|
|
|
|
<p class="mb-0" v-if="tokens.length === 0">
|
|
|
|
|
You have not created any personal access tokens.
|
|
|
|
|
</p>
|
|
|
|
|
|
|
|
|
|
<!-- Personal Access Tokens -->
|
|
|
|
|
<table class="table table-borderless mb-0" v-if="tokens.length > 0">
|
|
|
|
|
<thead>
|
|
|
|
|
<tr>
|
|
|
|
|
<th>Name</th>
|
|
|
|
|
<th>Scopes</th>
|
|
|
|
|
<th>Expires</th>
|
|
|
|
|
<th></th>
|
|
|
|
|
</tr>
|
|
|
|
|
</thead>
|
|
|
|
|
|
|
|
|
|
<tbody>
|
|
|
|
|
<tr v-for="token in tokens">
|
|
|
|
|
<!-- Client Name -->
|
|
|
|
|
<tr v-for="token in tokens" :key="token.id">
|
|
|
|
|
<td style="vertical-align: middle;">
|
|
|
|
|
{{ token.name }}
|
|
|
|
|
<div class="font-weight-bold">{{ token.name }}</div>
|
|
|
|
|
<small class="text-muted" v-if="token.created_at" style="font-size:12px;">
|
|
|
|
|
Created {{ formatDate(token.created_at) }}
|
|
|
|
|
</small>
|
|
|
|
|
</td>
|
|
|
|
|
|
|
|
|
|
<!-- Delete Button -->
|
|
|
|
|
<td style="vertical-align: middle;">
|
|
|
|
|
<a class="action-link text-danger" @click="revoke(token)">
|
|
|
|
|
<template v-if="token.scopes && token.scopes.length > 0">
|
|
|
|
|
<span v-for="scope in token.scopes"
|
|
|
|
|
:key="scope"
|
|
|
|
|
class="badge mr-1 mb-1"
|
|
|
|
|
:class="getScopeBadge(scope)">
|
|
|
|
|
{{ scope === '*' ? 'all scopes' : scope }}
|
|
|
|
|
</span>
|
|
|
|
|
</template>
|
|
|
|
|
<span v-else class="text-muted">—</span>
|
|
|
|
|
</td>
|
|
|
|
|
|
|
|
|
|
<td style="vertical-align: middle;">
|
|
|
|
|
<span v-if="! token.expires_at" class="text-muted text-xs">
|
|
|
|
|
Never
|
|
|
|
|
</span>
|
|
|
|
|
<span v-else
|
|
|
|
|
:class="{ 'text-danger': isExpired(token) }"
|
|
|
|
|
style="font-size:12px;"
|
|
|
|
|
:title="formatDate(token.expires_at)">
|
|
|
|
|
{{ formatDate(token.expires_at) }}
|
|
|
|
|
<span v-if="isExpired(token)" class="font-weight-bold">(expired)</span>
|
|
|
|
|
</span>
|
|
|
|
|
</td>
|
|
|
|
|
|
|
|
|
|
<td style="vertical-align: middle;" class="text-right">
|
|
|
|
|
<a class="btn btn-danger btn-sm" style="font-weight: bold;" @click="revoke(token)">
|
|
|
|
|
Delete
|
|
|
|
|
</a>
|
|
|
|
|
</td>
|
|
|
|
|
@ -55,7 +81,6 @@
|
|
|
|
|
</div>
|
|
|
|
|
</div>
|
|
|
|
|
|
|
|
|
|
<!-- Create Token Modal -->
|
|
|
|
|
<div class="modal fade" id="modal-create-token" tabindex="-1" role="dialog">
|
|
|
|
|
<div class="modal-dialog">
|
|
|
|
|
<div class="modal-content">
|
|
|
|
|
@ -68,20 +93,17 @@
|
|
|
|
|
</div>
|
|
|
|
|
|
|
|
|
|
<div class="modal-body">
|
|
|
|
|
<!-- Form Errors -->
|
|
|
|
|
<div class="alert alert-danger" v-if="form.errors.length > 0">
|
|
|
|
|
<p class="mb-0"><strong>Whoops!</strong> Something went wrong!</p>
|
|
|
|
|
<br>
|
|
|
|
|
<ul>
|
|
|
|
|
<li v-for="error in form.errors">
|
|
|
|
|
<li v-for="(error, index) in form.errors" :key="index">
|
|
|
|
|
{{ error }}
|
|
|
|
|
</li>
|
|
|
|
|
</ul>
|
|
|
|
|
</div>
|
|
|
|
|
|
|
|
|
|
<!-- Create Token Form -->
|
|
|
|
|
<form role="form" @submit.prevent="store">
|
|
|
|
|
<!-- Name -->
|
|
|
|
|
<div class="form-group row">
|
|
|
|
|
<label class="col-md-4 col-form-label">Name</label>
|
|
|
|
|
|
|
|
|
|
@ -90,12 +112,11 @@
|
|
|
|
|
</div>
|
|
|
|
|
</div>
|
|
|
|
|
|
|
|
|
|
<!-- Scopes -->
|
|
|
|
|
<div class="form-group row" v-if="scopes.length > 0">
|
|
|
|
|
<label class="col-md-4 col-form-label">Scopes</label>
|
|
|
|
|
|
|
|
|
|
<div class="col-md-6">
|
|
|
|
|
<div v-for="scope in scopes">
|
|
|
|
|
<div v-for="scope in scopes" :key="scope.id">
|
|
|
|
|
<div class="checkbox">
|
|
|
|
|
<label>
|
|
|
|
|
<input type="checkbox"
|
|
|
|
|
@ -104,6 +125,9 @@
|
|
|
|
|
|
|
|
|
|
{{ scope.id }}
|
|
|
|
|
</label>
|
|
|
|
|
<small class="text-muted d-block ml-4" v-if="scope.description">
|
|
|
|
|
{{ scope.description }}
|
|
|
|
|
</small>
|
|
|
|
|
</div>
|
|
|
|
|
</div>
|
|
|
|
|
</div>
|
|
|
|
|
@ -111,7 +135,6 @@
|
|
|
|
|
</form>
|
|
|
|
|
</div>
|
|
|
|
|
|
|
|
|
|
<!-- Modal Actions -->
|
|
|
|
|
<div class="modal-footer">
|
|
|
|
|
<button type="button" class="btn btn-secondary font-weight-bold" data-dismiss="modal">Close</button>
|
|
|
|
|
|
|
|
|
|
@ -123,7 +146,6 @@
|
|
|
|
|
</div>
|
|
|
|
|
</div>
|
|
|
|
|
|
|
|
|
|
<!-- Access Token Modal -->
|
|
|
|
|
<div class="modal fade" id="modal-access-token" tabindex="-1" role="dialog">
|
|
|
|
|
<div class="modal-dialog">
|
|
|
|
|
<div class="modal-content">
|
|
|
|
|
@ -141,10 +163,9 @@
|
|
|
|
|
You may now use this token to make API requests.
|
|
|
|
|
</p>
|
|
|
|
|
|
|
|
|
|
<textarea class="form-control" rows="10">{{ accessToken }}</textarea>
|
|
|
|
|
<textarea class="form-control" rows="10" readonly>{{ accessToken }}</textarea>
|
|
|
|
|
</div>
|
|
|
|
|
|
|
|
|
|
<!-- Modal Actions -->
|
|
|
|
|
<div class="modal-footer">
|
|
|
|
|
<button type="button" class="btn btn-secondary" data-dismiss="modal">Close</button>
|
|
|
|
|
</div>
|
|
|
|
|
@ -156,9 +177,6 @@
|
|
|
|
|
|
|
|
|
|
<script>
|
|
|
|
|
export default {
|
|
|
|
|
/*
|
|
|
|
|
* The component's data.
|
|
|
|
|
*/
|
|
|
|
|
data() {
|
|
|
|
|
return {
|
|
|
|
|
accessToken: null,
|
|
|
|
|
@ -174,24 +192,12 @@
|
|
|
|
|
};
|
|
|
|
|
},
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Prepare the component (Vue 1.x).
|
|
|
|
|
*/
|
|
|
|
|
ready() {
|
|
|
|
|
this.prepareComponent();
|
|
|
|
|
},
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Prepare the component (Vue 2.x).
|
|
|
|
|
*/
|
|
|
|
|
mounted() {
|
|
|
|
|
this.prepareComponent();
|
|
|
|
|
},
|
|
|
|
|
|
|
|
|
|
methods: {
|
|
|
|
|
/**
|
|
|
|
|
* Prepare the component.
|
|
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
prepareComponent() {
|
|
|
|
|
this.getTokens();
|
|
|
|
|
this.getScopes();
|
|
|
|
|
@ -201,9 +207,35 @@
|
|
|
|
|
});
|
|
|
|
|
},
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Get all of the personal access tokens for the user.
|
|
|
|
|
*/
|
|
|
|
|
getScopeBadge(scope) {
|
|
|
|
|
switch (scope) {
|
|
|
|
|
case '*':
|
|
|
|
|
return 'badge-danger';
|
|
|
|
|
break;
|
|
|
|
|
|
|
|
|
|
case 'read':
|
|
|
|
|
return 'badge-secondary';
|
|
|
|
|
break;
|
|
|
|
|
|
|
|
|
|
case 'push':
|
|
|
|
|
return 'badge-info';
|
|
|
|
|
break;
|
|
|
|
|
|
|
|
|
|
case 'write':
|
|
|
|
|
case 'follow':
|
|
|
|
|
case 'admin:read':
|
|
|
|
|
case 'admin:read:domain_blocks':
|
|
|
|
|
case 'admin:write':
|
|
|
|
|
case 'admin:write:domain_blocks':
|
|
|
|
|
return 'badge-danger';
|
|
|
|
|
break;
|
|
|
|
|
|
|
|
|
|
default:
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
},
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
getTokens() {
|
|
|
|
|
axios.get('/oauth/personal-access-tokens')
|
|
|
|
|
.then(response => {
|
|
|
|
|
@ -211,9 +243,6 @@
|
|
|
|
|
});
|
|
|
|
|
},
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Get all of the available scopes.
|
|
|
|
|
*/
|
|
|
|
|
getScopes() {
|
|
|
|
|
axios.get('/oauth/scopes')
|
|
|
|
|
.then(response => {
|
|
|
|
|
@ -221,16 +250,10 @@
|
|
|
|
|
});
|
|
|
|
|
},
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Show the form for creating new tokens.
|
|
|
|
|
*/
|
|
|
|
|
showCreateTokenForm() {
|
|
|
|
|
$('#modal-create-token').modal('show');
|
|
|
|
|
},
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Create a new personal access token.
|
|
|
|
|
*/
|
|
|
|
|
store() {
|
|
|
|
|
this.accessToken = null;
|
|
|
|
|
|
|
|
|
|
@ -255,27 +278,18 @@
|
|
|
|
|
});
|
|
|
|
|
},
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Toggle the given scope in the list of assigned scopes.
|
|
|
|
|
*/
|
|
|
|
|
toggleScope(scope) {
|
|
|
|
|
if (this.scopeIsAssigned(scope)) {
|
|
|
|
|
this.form.scopes = _.reject(this.form.scopes, s => s == scope);
|
|
|
|
|
this.form.scopes = _.reject(this.form.scopes, s => s === scope);
|
|
|
|
|
} else {
|
|
|
|
|
this.form.scopes.push(scope);
|
|
|
|
|
}
|
|
|
|
|
},
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Determine if the given scope has been assigned to the token.
|
|
|
|
|
*/
|
|
|
|
|
scopeIsAssigned(scope) {
|
|
|
|
|
return _.indexOf(this.form.scopes, scope) >= 0;
|
|
|
|
|
},
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Show the given access token to the user.
|
|
|
|
|
*/
|
|
|
|
|
showAccessToken(accessToken) {
|
|
|
|
|
$('#modal-create-token').modal('hide');
|
|
|
|
|
|
|
|
|
|
@ -284,14 +298,37 @@
|
|
|
|
|
$('#modal-access-token').modal('show');
|
|
|
|
|
},
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Revoke the given token.
|
|
|
|
|
*/
|
|
|
|
|
revoke(token) {
|
|
|
|
|
if (! window.confirm('Delete this token? Any applications using it will stop working immediately.')) {
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
axios.delete('/oauth/personal-access-tokens/' + token.id)
|
|
|
|
|
.then(response => {
|
|
|
|
|
.then(() => {
|
|
|
|
|
this.getTokens();
|
|
|
|
|
});
|
|
|
|
|
},
|
|
|
|
|
|
|
|
|
|
formatDate(value) {
|
|
|
|
|
if (! value) {
|
|
|
|
|
return '';
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
const date = new Date(value);
|
|
|
|
|
|
|
|
|
|
if (isNaN(date.getTime())) {
|
|
|
|
|
return value;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return date.toLocaleString(undefined, {
|
|
|
|
|
year: 'numeric',
|
|
|
|
|
month: 'short',
|
|
|
|
|
day: 'numeric',
|
|
|
|
|
});
|
|
|
|
|
},
|
|
|
|
|
|
|
|
|
|
isExpired(token) {
|
|
|
|
|
return !! token.expires_at && new Date(token.expires_at).getTime() < Date.now();
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|