Publishing Configuration
The configuration is published automatically during the installation process to config/larascord.php.
You can publish Larascord's configuration using the following commands:
php artisan larascord:publishphp artisan vendor:publish --provider="Jakyeru\Larascord\LarascordServiceProvider" --tag="larascord-config"You can also forcefully publish Larascord's configuration, overwriting any existing configuration:
php artisan larascord:publish --forcePublishing Migrations
You can publish Larascord's migrations using the following commands:
php artisan larascord:publish --migrationsphp artisan vendor:publish --provider="Jakyeru\Larascord\LarascordServiceProvider" --tag="larascord-migrations"Environment variables
| Variable | Default | Description |
|---|---|---|
LARASCORD_CLIENT_ID | The ID of your Discord application. | |
LARASCORD_CLIENT_SECRET | The secret of your Discord application. | |
LARASCORD_ACCESS_TOKEN | Your bot's token. Only needed for the guilds.join scope. | |
LARASCORD_PREFIX | larascord | The prefix Larascord's routes live under. |
LARASCORD_SCOPES | identify,email | A comma separated list of OAuth2 scopes. |
LARASCORD_REDIRECT_URI | APP_URL/LARASCORD_PREFIX/callback | The callback URL registered with Discord. |
LARASCORD_LOGIN_ALIAS | false | Whether to register a /login route named login. |
LARASCORD_GUARD | web | The guard Larascord logs the user in and out with. |
LARASCORD_USER_MODEL | App\Models\User | Your application's user model. |
LARASCORD_CACHE_STORE | default store | The cache store used by the guild and role middleware. |
LARASCORD_REQUIRE_VERIFIED | false | Whether only Discord accounts with a verified e-mail address can log in. |
LARASCORD_DB_CONNECTION | The connection Larascord's tables live on. | |
LARASCORD_PROMPT | none | Either none or consent. |
⚠️
LARASCORD_SCOPE was renamed to LARASCORD_SCOPES in version 8. It takes a comma separated list instead of an & separated one.
Configuration
return [
/*
|--------------------------------------------------------------------------
| Application ID
|--------------------------------------------------------------------------
|
| This is the ID of your Discord application.
|
*/
'client_id' => env('LARASCORD_CLIENT_ID'),
/*
|--------------------------------------------------------------------------
| Application Secret
|--------------------------------------------------------------------------
|
| This is the secret of your Discord application.
|
*/
'client_secret' => env('LARASCORD_CLIENT_SECRET'),
/*
|--------------------------------------------------------------------------
| Application Access Token
|--------------------------------------------------------------------------
|
| This is the bot token of your Discord application. It is only required if
| you want to add users to a guild through the "guilds.join" scope.
|
*/
'access_token' => env('LARASCORD_ACCESS_TOKEN'),
/*
|--------------------------------------------------------------------------
| Grant Type
|--------------------------------------------------------------------------
|
| This is the grant type of your Discord application. It must be set to
| "authorization_code".
|
*/
'grant_type' => env('LARASCORD_GRANT_TYPE', 'authorization_code'),
/*
|--------------------------------------------------------------------------
| Redirect URI
|--------------------------------------------------------------------------
|
| This is the URI that Discord will redirect to after the user authorizes
| your application. It has to match one of the redirect URLs listed in the
| OAuth2 tab of your Discord application.
|
*/
'redirect_uri' => env('LARASCORD_REDIRECT_URI', env('APP_URL', 'http://localhost:8000') . '/' . env('LARASCORD_PREFIX', 'larascord') . '/callback'),
/*
|--------------------------------------------------------------------------
| Scopes
|--------------------------------------------------------------------------
|
| These are the OAuth2 scopes Larascord will ask Discord for.
|
*/
'scopes' => array_values(array_filter(array_map('trim', explode(',', env('LARASCORD_SCOPES', 'identify,email'))))),
/*
|--------------------------------------------------------------------------
| OAuth2 Prompt - "none" or "consent"
|--------------------------------------------------------------------------
|
| The prompt controls how the authorization flow handles existing authorizations.
| If a user has previously authorized your application with the requested scopes
| and prompt is set to consent,it will request them to re-approve their
| authorization. If set to none, it will skip the authorization screen
| and redirect them back to your redirect URI without requesting
| their authorization.
|
*/
'prompt' => env('LARASCORD_PROMPT', 'none'),
/*
|--------------------------------------------------------------------------
| State Verification
|--------------------------------------------------------------------------
|
| A random "state" parameter is sent to Discord and verified on the
| callback, which protects the route against cross-site request
| forgery. Disable this only when the authorization URL is built
| outside of Larascord and the state cannot be kept in session.
|
*/
'verify_state' => true,
/*
|--------------------------------------------------------------------------
| Routes
|--------------------------------------------------------------------------
|
| Routes are registered under the prefix below and named with a
| "larascord." prefix. Set "enabled" to false to register your own
| routes against Jakyeru\Larascord\Http\Controllers\DiscordController.
|
| The "login_alias" option registers a "/login" route named "login" that
| redirects to Discord. Keep it disabled if the application already
| registers a route with that name.
|
*/
'routes' => [
'enabled' => true,
'prefix' => env('LARASCORD_PREFIX', 'larascord'),
'middleware' => ['web'],
'authenticated_middleware' => ['web', 'auth'],
'login_alias' => env('LARASCORD_LOGIN_ALIAS', false),
],
/*
|--------------------------------------------------------------------------
| Authentication Guard
|--------------------------------------------------------------------------
|
| This is the guard Larascord uses to log the user in and out.
|
*/
'guard' => env('LARASCORD_GUARD', 'web'),
/*
|--------------------------------------------------------------------------
| Users
|--------------------------------------------------------------------------
|
| The Discord profile is stored in the table configured below and linked
| to this model through a "user_id" foreign key.
|
| The "attributes" array maps the columns of your users table to the
| attributes of the Discord profile. Available attributes are: id,
| username, global_name, display_name, discriminator, avatar,
| email, verified, banner, banner_color, accent_color,
| locale, mfa_enabled, premium_type, public_flags.
|
| "link_by_email" matches the e-mail address of the Discord account
| against the column set in "email_column" and links the account to
| the user it belongs to.
|
| "create_missing" determines whether a user is created when no existing
| user is matched. When disabled, the login is rejected instead.
|
| "fill_random_password" fills a "password" column that is not present in
| the "attributes" array with a hashed random string. It applies only
| when the column exists on the users table.
|
*/
'users' => [
'model' => env('LARASCORD_USER_MODEL', 'App\Models\User'),
'email_column' => 'email',
'attributes' => [
'name' => 'display_name',
'email' => 'email',
],
'link_by_email' => true,
'create_missing' => true,
'fill_random_password' => true,
],
/*
|--------------------------------------------------------------------------
| Require a Verified Discord Account
|--------------------------------------------------------------------------
|
| When enabled, only Discord accounts with a verified e-mail address can
| log in or be linked. Unverified accounts are rejected before a user
| is created. This requires the "email" scope.
|
*/
'require_verified' => env('LARASCORD_REQUIRE_VERIFIED', false),
/*
|--------------------------------------------------------------------------
| Database
|--------------------------------------------------------------------------
|
| These are the tables created by Larascord's migrations.
|
| Set "foreign_keys" to false when the users table is on another
| connection or does not support foreign key constraints.
|
*/
'database' => [
'connection' => env('LARASCORD_DB_CONNECTION'),
'accounts_table' => 'larascord_accounts',
'access_tokens_table' => 'larascord_access_tokens',
'foreign_keys' => true,
],
/*
|--------------------------------------------------------------------------
| Restrict Access to Specific Guilds
|--------------------------------------------------------------------------
|
| This option restricts access to the application to users who are members
| of specific Discord guilds. Users who are not members of the specified
| guilds will not be able to use the application.
|
*/
'guilds' => [],
/*
|--------------------------------------------------------------------------
| Restrict Access to Specific Guilds - Strict Mode
|--------------------------------------------------------------------------
|
| Enabling this option will require the user to be a member of ALL the
| aforementioned guilds. If this option is disabled, the user will
| only need to be a member of at least ONE of the guilds.
|
*/
'guilds_strict' => false,
/*
|--------------------------------------------------------------------------
| Restrict Access to Specific Roles
|--------------------------------------------------------------------------
|
| When this option is enabled, the user will only be able to use the
| application if they have at least one of the specified roles.
|
*/
// WARNING: This feature makes one request to the Discord API for each guild you specify. (Because you need to fetch the roles for each guild)
'guild_roles' => [
// 'guild_id' => [
// 'role_id',
// 'role_id',
// ],
],
/*
|--------------------------------------------------------------------------
| Guild and Role Middleware
|--------------------------------------------------------------------------
|
| The "discord.guild" and "discord.role" middleware check the user's
| guilds and roles on every request, so access ends when the user
| leaves a guild or loses a role. Results are cached for "ttl"
| seconds and cleared whenever the user logs in again.
|
*/
'access_cache' => [
'ttl' => 300,
'store' => env('LARASCORD_CACHE_STORE'),
],
/*
|--------------------------------------------------------------------------
| Remember Me
|--------------------------------------------------------------------------
|
| Whether or not to remember the user after they log in.
|
*/
'remember_me' => false,
/*
|--------------------------------------------------------------------------
| Redirects
|--------------------------------------------------------------------------
|
| Where the user is redirected after logging in, after logging out and
| after unlinking their Discord account. These are used as fallbacks
| when no return URL was resolved when the flow started.
|
*/
'redirect_login' => '/',
'redirect_logout' => '/',
'redirect_unlink' => '/',
/*
|--------------------------------------------------------------------------
| Error Messages
|--------------------------------------------------------------------------
|
| These are the error messages that will be displayed to the user if there
| is an error.
|
*/
'error_messages' => [
'missing_code' => [
'message' => 'The authorization code is missing.',
'redirect' => '/'
],
'invalid_code' => [
'message' => 'The authorization code is invalid.',
'redirect' => '/'
],
'invalid_state' => [
'message' => 'The login attempt has expired. Please try again.',
'redirect' => '/'
],
'authorization_failed' => [
'message' => 'The authorization failed.',
'redirect' => '/'
],
'missing_email' => [
'message' => 'Couldn\'t get your e-mail address.',
'redirect' => '/'
],
'missing_email_scope' => [
'message' => 'The "email" scope is required to check that the Discord account is verified.',
'redirect' => '/'
],
'unverified_account' => [
'message' => 'Verify the e-mail address of your Discord account, then log in again.',
'redirect' => '/'
],
'account_already_linked' => [
'message' => 'This Discord account is already linked to another user.',
'redirect' => '/'
],
'registration_disabled' => [
'message' => 'There is no account matching your Discord account.',
'redirect' => '/'
],
'database_error' => [
'message' => 'There was an error with the database. Please try again later.',
'redirect' => '/'
],
'missing_guilds_scope' => [
'message' => 'The "guilds" scope is required.',
'redirect' => '/'
],
'missing_guilds_members_read_scope' => [
'message' => 'The "guilds" and "guilds.members.read" scopes are required.',
'redirect' => '/'
],
'authorization_failed_guilds' => [
'message' => 'Couldn\'t get the servers you\'re in.',
'redirect' => '/'
],
'not_member_guild_only' => [
'message' => 'You are not a member of the required guilds.',
'redirect' => '/'
],
'missing_access_token' => [
'message' => 'The access token is missing.',
'redirect' => '/'
],
'authorization_failed_roles' => [
'message' => 'Couldn\'t get the roles you have.',
'redirect' => '/'
],
'missing_role' => [
'message' => 'You don\'t have the required roles.',
'redirect' => '/'
],
'revoke_token_failed' => [
'message' => 'An error occurred while trying to revoke your access token.',
'redirect' => '/'
],
'missing_discord_account' => [
'message' => 'You don\'t have a Discord account linked.',
'redirect' => '/'
],
],
/*
|--------------------------------------------------------------------------
| Success Messages
|--------------------------------------------------------------------------
|
| These are the success messages that will be displayed to the user if there
| is no error.
|
*/
'success_messages' => [
'account_linked' => [
'message' => 'Your Discord account has been linked.',
'redirect' => null
],
'account_unlinked' => [
'message' => 'Your Discord account has been unlinked.',
'redirect' => null
],
],
];