1

I'm using laravel 5.2.45 and I have the following routes

Route::group([
    'namespace' => 'Api',
    'prefix' => "api",
    'middleware' => 'service'
], function() {

    Route::get('student/{msisdn}/status', 'StudentController@status');

});

my middleware is service so here is my config/service.php

<?php 

return [
    'password' => //password here,
    'ip' => //my server ip here,
    'url' => [
        'check_status' => 'http://%s/student/api/checkUser?password=%s&msisdn=%s',

    ]
];

This code works fine according to my requirements, but what i want now is to apply basic authentication without database. I just want a hardcorded username and password (its my requirements, otherwise i would use db).

As my middleware is service and how will i apply another middleware basic.auth on it, is it possible to use two middleware ? or combine both service and basic.auth middle ware and create new middleware? any suggestion, tutorial or example code on how can i do that?

1 Answer 1

3

You can add any number of middleware to a route or group of routes.

Route::group([
    'namespace' => 'Api',
    'prefix' => "api",
    'middleware' => ['service', 'auth.basic']
], function() {
    Route::get('student/{msisdn}/status', 'StudentController@status');
});

As for authentication without a database, you can create a custom middleware and hardcode the login information there. Apply this middleware to all the routes to enforce the auth.

This should get you started. Though you need to convert the filter to a middleware, the code here is pretty straightforward.

https://stackoverflow.com/a/28322507/5892849

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.