Giter Club home page Giter Club logo

laravel-janitor's Introduction

Easily add login proxy to your Laravel API

Latest Version on Packagist Tests StyleCI Quality Score Total Downloads

The signifly/laravel-janitor package allows you to easily add a login proxy to your Laravel API.

You can find two articles that walk you through getting started using:

Documentation

To get started you have to either install laravel/passport or tymon/jwt-auth. Please refer to their documentation for how to configure those packages.

NOTE: For now the supported versions for tymon/jwt-auth is 1.0.0-rc.*.

Installation

You can install the package via composer:

composer require signifly/laravel-janitor

The package will automatically register itself.

You can optionally publish the config file with:

php artisan vendor:publish --tag="janitor-config"

After pulling in the package and (optionally) publishing the config, then add the routes to your routes/api.php file:

Janitor::routes();

It will by default add routes for the following:

  • login by username and password (/login)
  • refresh current user access token (/login/refresh)
  • log the user out (/logout)
  • send password reset email (/password/email)
  • reset password (/password/reset)

You can also define a specific set of routes by passing a Closure:

Janitor::routes(function ($router) {
    // Login and logout routes
    $router->forAuthentication();

    // Password reset routes
    $router->forPasswordReset();
});

Finally, add JANITOR_DRIVER=driver-name to your .env file.

The supported drivers are: passport and jwt.

NOTE: It does not support a default driver and throws an InvalidArgumentException if omitted.

Resetting passwords

In order to use the reset password implementation in an API, you have to add a custom reset password notification to your user model.

// App\User.php

/**
 * Send the password reset notification.
 *
 * @param  string  $token
 * @return void
 */
public function sendPasswordResetNotification($token)
{
    $this->notify(new ResetPasswordNotification($token));
}

The notification should format a correct link to your client app's reset password url.

Testing

composer test

Security

If you discover any security issues, please email [email protected] instead of using the issue tracker.

Credits

License

The MIT License (MIT). Please see License File for more information.

laravel-janitor's People

Contributors

connors511 avatar pactode avatar razorsheep avatar seriousjelly 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  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  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  avatar

laravel-janitor's Issues

Consider Getting Model Name from Passport

$client = DB::table('oauth_clients')

One can ask Passport for the client name or model.

https://github.com/laravel/passport/blob/5e4f98db1c801c3f05b3039270d4cd9cd09fa3fc/src/Passport.php#L476

https://github.com/laravel/passport/blob/5e4f98db1c801c3f05b3039270d4cd9cd09fa3fc/src/Passport.php#L486

    /**
     * Get a new client model instance.
     *
     * @return \Laravel\Passport\Client
     */
    public static function client()
    {
        return new static::$clientModel;
    }

You probably want the latter; it's technically less likely to fall over (although I don't see upstream renaming the oauth_* tables any time soon).

Laravel v6

Will you add support for laravel 6 and when? Tnx for awesome package!

Getting "These credentials do not match our records." error when trying to login with user that does exists

As said, I am getting "InvalidClientCredentialsException" when trying to log in as an user that does exists:

/** @test */
public function should_login()
{
    $user = factory(User::class)->create([
        'email' => '[email protected]',
        'password' => $password = bcrypt('secret')
    ]);

    $this->assertDatabaseHas('users', [
        'email' => '[email protected]',
        'password' => $password
    ]); // this passes

    $this
        ->withoutExceptionHandling()
        ->json('POST', 'api/login', [
            'email' => $user->email,
            'password' => 'secret'
        ])
        ->assertStatus(200);
}

What could be the issue?

I am using passport driver.

EDIT: OK, I Added the $this->artisan('passport:install'); line but now I get the other exception:
GuzzleHttp\Exception\ConnectException : cURL error 7: Failed to connect to 127.0.0.1 port 80: Connection refused

I made a custom proxy and there it works.

Client ID field as a UUID

Great package! Thanks for this, it has helped me out.

A couple of issues/questions:

  1. It would be great if we had the ability to override the Passport model used. In my app I have extended the Passport model to allow for the ID column to be UUID's. At the moment, my application fails as the Client ID that is returned from getClientCredentials() function is 2 when in actual fact it is 02f5b33a-5735-4fe6-87bf-2e062d745271.

  2. Allow for the ability to define a client, as it stands it just grabs the first password client.

Laravel 8 Support

Hi there,

thanks for your awesome package!

I was just trying to upgrade my project to Laravel 8. I get an error that the guzzle-dependency doesn't work at the same time as the requirement for Laravel 8 (which is ^7.0.1).
On the other hand I saw that you commited some changes focusing on Laravel 8 support already a month ago. Perhaps it's just a matter of setting up a release for composer?

Thanks in advance!
Chris

PHP Doc

None of the code seems to have PHP Doc.

PHP 8 Support

Hello,

Due to composer requirements, its unable to install with PHP 8. Are there any plan for supporting PHP 8?

Laravel 9 support

Hi,

First of all, thanks for this package.
Can you update the composer.json file in order to support Laravel 9?

Thanks in advance!

Other Clients?

protected function getClientCredentials()

This fetches the first client, however it is possible for there to be more than one client.

Is there any plan to support:

  • Setting a default client by configuration?
  • Selecting a client somehow?

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.