Code Monkey home page Code Monkey logo

super-basic-auth's Introduction

super-basic-auth

Super Basic Auth

Latest Version on Packagist Total Downloads Software License Build Status StyleCI

This is a super lightweight package to add the most basic form of authentication to your Laravel app. All you need is a webserver and a text editor!

Installation

The installation instructions for this package can be found below.

Downloading

Via composer:

$ composer require sven/super-basic-auth

Or add the package to your dependencies in composer.json and run composer update on the command line to download it:

{
    "require": {
        "sven/super-basic-auth": "^2.3"
    }
}

Usage

To use this package, first add the following code to your config/auth.php file:

return [
    // ...

    'basic' => [
        'user' => env('AUTH_USERNAME'),
        'password' => env('AUTH_PASSWORD'),
    ],
];

Be sure to add AUTH_USERNAME and AUTH_PASSWORD to your .env file. You can call these entries whatever you want.

Finally, apply the middleware to any route you want protected by those credentials:

Route::group('admin', function () {
    // Your password protected routes.
})->middleware(\Sven\SuperBasicAuth\SuperBasicAuth::class);

Contributing

All contributions (pull requests, issues and feature requests) are welcome. Make sure to read through the CONTRIBUTING.md first, though. See the contributors page for all contributors.

License

sven/super-basic-auth is licensed under the MIT License (MIT). Please see the license file for more information.

super-basic-auth's People

Contributors

dependabot[bot] avatar svenluijten avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar

super-basic-auth's Issues

Add ability to check if user is authenticated or not

There should be a way to this this with the headers being sent from the browser ($request->getUser(), $request->getPassword()).

How should this be accessed?

  • Dependency injection
  • Helper method
  • Facade

This should be completely optional, so users should still be able to just include the middleware and be on their way. This can be done in a minor release, so it'd become 1.1.0.

The middleware can be edited to make use of this new way to determine if the user is logged in.

Applying the middleware to routes that redirect breaks

Return value of Sven\SuperBasicAuth\SuperBasicAuth::handle() must be an instance of Illuminate\Http\Response, instance of Illuminate\Http\RedirectResponse returned

Seems to be related to the return typehint in the middleware, this should probably be Symfony's \Symfony\Component\HttpFoundation\Response instead of \Illuminate\Http\Response. Or drop the return typehint completely ๐Ÿคทโ€โ™‚

If the config values are not filled in, middleware is fine

If the user does not fill out the config values (auth.basic.user and auth.basic.password), they evaluate to null, which is also what $request->getUser(); and $request->getPassword(); return.

So this check will always return true. Maybe add an extra null check in there ๐Ÿ˜…

if ($request->getUser() === config('auth.basic.user') &&
$request->getPassword() === config('auth.basic.password')

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.