Replies: 1 comment
-
Hi @ap250733, How are you authenticating with Postman? If you're trying to use a session driver with your API routes, the session isn't likely being setup due to Notice how the If you're using Sanctum, you will have to create your own API authentication route that creates a Sanctum API token after you https://laravel.com/docs/9.x/sanctum#issuing-mobile-api-tokens Here is their example: use App\Models\User;
use Illuminate\Http\Request;
use Illuminate\Support\Facades\Hash;
use Illuminate\Validation\ValidationException;
Route::post('/sanctum/token', function (Request $request) {
$request->validate([
'email' => 'required|email',
'password' => 'required',
'device_name' => 'required',
]);
$user = User::where('email', $request->email)->first();
if (! $user || ! Hash::check($request->password, $user->password)) {
throw ValidationException::withMessages([
'email' => ['The provided credentials are incorrect.'],
]);
}
return $user->createToken($request->device_name)->plainTextToken;
}); You could modify the above controller to work with LdpRecord with an Route::post('/sanctum/token', function (Request $request) {
$request->validate([
'email' => 'required|email',
'password' => 'required',
'device_name' => 'required',
]);
$ldapCredentials = [
'mail' => $request->email,
'password' => $request->password,
];
if (! Auth::validate($ldapCredentials)) {
throw ValidationException::withMessages([
'email' => ['The provided credentials are incorrect.'],
]);
}
return Auth::getLastAttempted()->createToken($request->device_name)->plainTextToken;
}); Once you've authenticated and have received the plain text token via your auth route above, you will then keep that token to authenticate further requests with Postman by placing the token inside of an |
Beta Was this translation helpful? Give feedback.
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
-
Hello, I can log in fine to my LDAP server but when I try to access the Auth::user() in my API route through my controller, I'm getting null. I've tried enabling middleware => auth for my routes but in postman I'm getting
{ "message": "Unauthenticated." }
I've tried installing sanctum, but I can't find any resources online on exactly how to use it while incorporating ldaprecord-laravel. Any ideas would be appreicated, I can post any code snippets as needed. Forgive me if I made any mistakes, I'm still a beginner.
Here is my
routes/api.php
Here is my
config/auth.php
Any help, ideas would be appreciated, thank you.
Beta Was this translation helpful? Give feedback.
All reactions