I have been making research to switch to a community supported authorization system rather than the one I've built. I made the mistake of rebuilding the wheel, instead of implementing a community driven system that utilizes the best practices. However, I couldn't find any authorization example with JWT rather than authentication.
I'm open to all suggestions. As far as I could find, JWT and OAuth requires clients to have an existing account, and authenticate in order to receive a token. However, I need the below functionality in my application.
I'm going to built this project with Laravel 5.1 and AngularJS. All suggestions are greatly appreciated. I really could use some directions on this, and simple links to documentations would be enough.
JWTs can be used as OAuth 2.0 Bearer Tokens to encode all relevant parts of an access token into the access token itself instead of having to store them in a database.
The OAuth access token is different from the JWT in the sense that it's an opaque token. The access token's purpose is so that the client application can query Google to ask for more information about the signed in user.
I think you can generate an anonymous access token either from a random existing user or from custom claims
From an Existing random user:
// grab some user
$user = User::first();
$token = JWTAuth::fromUser($user);
Or From Custom Claims:
$customClaims = ['foo' => 'bar', 'baz' => 'bob'];
$payload = JWTFactory::make($customClaims);
$token = JWTAuth::encode($payload);
You can get more details from the following link:
https://github.com/tymondesigns/jwt-auth/wiki/Creating-Tokens
I certainly understand the use case you describe - but I'd argue that an anonymous token doesn't actually add any security. This is because a completely anonymous user will be able to request an anonymous token without first identifying themselves (otherwise it wouldn't be anonymous). As such - this token must be assumed to be owned by any and all users of your application (including those with malicious intent)
Whilst I'm not familiar with Laravel - the general approach to achieving this sort of functionality might be something like:
authenticated
endpoints and anonymous
endpoints, requiring a valid access token present in the users session to retrieve/send data to those that are authenticated
authenticated
endpoint they have accessIf you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With