Is there a way to overwrite the GenericUser class in Laravel?
Current authentication uses GenericUser as a return object for Auth:: operartions,
I want it to be my User class from my model. Is this feasible?
The source you're looking at is DatabaseUserProvider. This provider works without models and will be used if your auth driver (in app/config/auth.php) is set to database.
What you're actually using is the EloquentUserProvider which uses the model class defined in the config. The default is 'model' => 'User' which is the User model Laravel ships with.
You can change that value to any class name. But make sure to implement the necessary interfaces and add the traits. You basically need pretty much everything the default User model has.
Laravel already uses the default User model supplied as the authentication model.
You can customise this further in config\auth.php. The default is to use 'model' => 'User', - but you can change it to be something else.
Related
I have a calculated field in a class used for photos which prepends a url to the filename, I want to be able to add a base url for the photos (which is to an azure storage account) which will come from the appsettings file.
Initially I created a strongly typed class to access the settings, and I can inject it just fine to say a service class, but how can I access this in a model class? Am I completely going in the wrong direction with this?
Thanks for any help!
When instantiating the model, you could inject your strongly typed settings class, as long as the model already has a dependency on that. Alternatively, you'd need to move the calculation of that field out of the model, or simply provide the base URL to the model from your service classes.
I'm new to ASP.NET Core and trying to build web api with Openiddict for security, what I'm looking for is a way to implement my own UserStore and other stores and use them ?
Is there an easy sample or example to follow ?
I tried to implement IUserStore and add it to IServiceCollection and used AddUserStore<MyUserStore>().
When I'm trying to execute identityUserManager.CreateAsync(user,..) I'm getting the following error.
The entity type
'Microsoft.AspNetCore.Identity.EntityFrameworkCore.IdentityUserLogin'
requires a primary key to be defined
I think the user class I'm creating and because it's inheriting from IdentityUser which is in Microsoft.AspNetCore.Identity.EntityFrameworkCore, causing this problem, now I didn't find another IdentityUser in another name space two inherit from, isn't there any ?
I'm struggling to figure out how to build a Core Data model to support the class structure I've created in my app.
My app has users, and I allow those users to log into the app using multiple different authentication methods. Each authentication method requires slightly different credentials and cred types. I've chosen to solve this by creating an abstract AuthenticationSettings base class, then subclass it with FacebookAuthenticationSettings, TwitterAuthenticationSettings, MyWebsiteAuthenticationSettings, etc.
My User class has a property authSettings (of type AuthenticationSettings), that stores an instance of one of the settings classes. Users are allowed only one auth method per user, so this works great.
The question is, how do I create a Core Data model for my users given that authSettings can have one of many object types stored to it?
Do I create separate entities for each type of authentication and then create relationships between those entities and the user entity? This is strange because the data model doesn't enforce 1:1 auth method to user. When fetching users, I'd also have to fetch their corresponding auth methods.
Do I just create my own serialization encoding of the auth creds and jam it into a string field on the user entity? This forces me to invent some encoding which feels especially messy if any future auth methods use fields that are difficult to serialize to string.
Is there a better way?
One way is to set up a Core Data entity hierarchy that parallels your class hierarchy. Create an abstract entity in Core Data called AuthenticationSettings and create a series of sub-entities for each authentication type. As with your User class property, create a relationship to AuthenticationSettings.
A simpler approach that sounds like it would meet your needs would be to make your various authentication classes conform to NSCoding, and then just store them in a single "transformable" (not string) field on the user entity. Core Data would then convert the authentication object to/from NSData automatically.
Does someone know how I can extend the dropwizard interface? Now it just have the required option, but I need to add rights for the anooteted method.
For example:
I have a user admin and a normal user. Both can authenticate and reaches my #auth annotated ressource. But I want to allow some (not all) http method request just for admins and dissalow for normal user. How can I do this outside of ressource? Something like
#Auth(required = true, right="admin", httpMethod="POST") User user)
#Auth(required = true, right="normalUser", httpMethod="GET") User user)
#Auth(required = true, right="masterOfTheuniverse", httpMethod="*") User user)
As annotation inheritance is not supported by Java; you can't.
I had a similar case so I had ended up copying the relevant classes from dropwizard and modify as I wished. I've combined AuthFilter with OAuthCredentialFilter as I didn't need the abstraction, and used my own class instead of Authenticator<C,P>.
Note: I've just realized, they have rewritten the #Auth logic using RequestFilters for the next release which looks more flexible and could meet your needs (I might just migrate to that too). The current version (0.8.x) uses Factorys, which you can find at Java8 implementation. Also the Auth annotation which is not in the master branch anymore.
When creating a Restful API in Zend Framework, can you use modules? If so, can one explain how? with an example pref. (or a link with supporting documents)
I have modules called:
Product
may have one controller
Entity
may have more than one controller eg.
/customer
/supplier
In each I have an Index Controller with the methods:
Get
Post
Put
Delete
Example:
Products/index/?id=1&name=test (will add)
However I want to remove the word index so its this instead:
Products/?id=1&name=test (will add)
I can do that with the help of Zend_Controller_Router_Route but it does not pass the request, ive looked at getMethod, but you can not do that at bootstrap stage.
Is there any way that you can use modular Zend Framework application as a restful API?
Yes you can.
You must use Zend_Rest_Route. It route the request by the method to the right action. There is one bug which prevents configuring the rest route in the configuration file, so you must add the route in the bootstrap.
<?php
protected function _initRestRoute()
{
$front = Zend_Controller_Front::getInstance();
$router = $front->getRouter();
$restRoute = new Zend_Rest_Route(
$front,
array(), //Defaults
array('api') //Restful modules
);
$router->addRoute('rest', $restRoute);
}
By default if you give a URL like this, the 123 is bind to the variable $id
products/123
You can also specify the Url like so, when the variables are bind '123' -> $id and 'test' -> $name
products/id/123/name/test
The controllers should extend the Zend_Rest_Controller class