Skip to content

JeffBeltran/sanctum-tokens

This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.

Folders and files

NameName
Last commit message
Last commit date

Latest commit

d1f0bb1 · Nov 7, 2023
Jun 26, 2022
Nov 7, 2023
Nov 7, 2023
Jun 26, 2022
May 13, 2023
Jun 26, 2022
Sep 17, 2021
Sep 17, 2021
May 13, 2023
Aug 23, 2020
Jun 27, 2022
Jun 26, 2022
May 13, 2023
Jun 26, 2022
Jun 27, 2022
Jun 26, 2022
May 13, 2023

Repository files navigation

Create a Sanctum Personal Access Tokens in Nova

This package allows you to use Sanctum to generate a Personal Access Tokens in Nova.

Screenshot

View without any tokens Create Token View Post Create Token View View with single token Revoke Token Prompt

Prerequisites

  1. Install and Configure Sanctum
  2. Have Laravel Nova
    • For Nova 4, use v2
    • Nova 3, use v1

Installation

composer require jeffbeltran/sanctum-tokens

Register the plugin by adding SanctumTokens::make() to the array of fields in the Nova resource. Make sure the HasApiTokens trait from the Sanctum package has been added to your model.

use Jeffbeltran\SanctumTokens\SanctumTokens;

/**
 * Get the fields displayed by the resource.
 *
 * @param  \Illuminate\Http\Request  $request
 * @return array
 */
public function fields(Request $request)
{
    return [
        ID::make('ID', 'id')->sortable(),
        ...
        SanctumTokens::make(),
    ];
}

Features

Hide Abilities

You can hide the reference to the token abilities from the UI by calling the hideAbilities() method on the field.

use Jeffbeltran\SanctumTokens\SanctumTokens;

/**
 * Get the fields displayed by the resource.
 *
 * @param  \Illuminate\Http\Request  $request
 * @return array
 */
public function fields(Request $request)
{
    return [
        ID::make('ID', 'id')->sortable(),
        ...
        SanctumTokens::make()->hideAbilities(),
    ];
}

Set Default Abilities

If you don't want to use the default * token ability you can set your own by simply passing an array of strings to the defaultAbilities() method on the field.

This works well with the the hideAbilities() method if you want to hide the abilities logic from your users.

use Jeffbeltran\SanctumTokens\SanctumTokens;

/**
 * Get the fields displayed by the resource.
 *
 * @param  \Illuminate\Http\Request  $request
 * @return array
 */
public function fields(Request $request)
{
    return [
        ID::make('ID', 'id')->sortable(),
        ...
        SanctumTokens::make()->defaultAbilities(['foo', 'bar-baz']),
    ];
}

Localization

Publish the package language files to your application's resources/lang/vendor directory:

php artisan vendor:publish --provider="Jeffbeltran\SanctumTokens\ToolServiceProvider"