ZfcUser: How do I do my own authentication? - php

I am facing the problem that I have to implement a way to authenticate a user against a SecurityService and, after that, get some data about him out of my database.
I want to use the ZfcUser Plugin and I am confused by Adapters, AdapterChains and AuthServices.
I really would appreciate some clarification about those classes and when to use them and in particular which one will be the type of class I have to use to communicate with my SecurityService.

Related

Seeding Laravel DB from external API

I'm new to Laravel. Maybe my questions are a little bit silly... Sorry...
The goal: There are some API resources and I need to take some selective data from them (It will be needed to make extra API queries from data which I already got before to get full sets of required values) and fill my DB tables with it (some as one to many, some as many to many).
The problem: What Laravel tools do I need to use to reach this goal? Is it factory, seeder or somewhat else? In addition I don't understand where I have to write the code for getting data from an external API and where (in terminal manually?) I have to initiate my DB tables filling.
Maybe someone could at least advise what to learn in the Laravel official documentation at first or some helpful reference to some article from which I will be clear how this process may be implemented in Laravel. I mean the tools' set and order to use them. Not the finished code implementation of course.
I will be grateful for any help. Thanks. Sorry for my non native English.
Well, there are multiple ways of achieving what you want:
One is to create a command where you are going to write code to fetch this data (using curl or any similar way). And then you manually run the command when you want with whatever arguments you want.
Other one is to use the previous step and schedule it to run in a desired time with desired arguments.
Other possible way is, if the external API can send data to a specific URL when some action occurs in that system, then you can create a normal Route and the API should point to this Route in your Laravel. It will be specific and only work for this API.
Other one is to fetch data based on an event. Let's say that, if a user register, when this is successful, you are going to fetch User info from an external API using their email (let's say you want to get a profile picture from an API and the only way to get the user picture is sending the user's email). You can do so using Events.
There are more ways, but if you don't give too much context, then this is what I can share with you !

Laravel: Know What to Implement in model

I am just about three days old in laravel, yesterday I tried creating an authentications system using eloquent, so without looking I deleted the default User model, and then I tried creating my own from what I had read from the documentation. After setting up every thing as I had studied and understood, I tried running my app, but whenever I enter the correct username and password I get this error
Argument 1 passed to Illuminate\Auth\EloquentUserProvider::validateCredentials()
must be an instance of Illuminate\Auth\UserInterface, instance of User given, called in dir
I did not know what the EloquentUserProvider was or where it was even coming from. My original model looked like this
class User extends Eloquent {}
I battled with this error for the whole day (no exaggeration), But today I found out from this SO Can't authenticate user in laravel that it was because I had not implemented some interface, so they linked me to https://github.com/laravel/laravel/blob/master/app/models/User.php where I copied the default model I initially deleted.
I used the documentation almost through out my learning process, and no where in the documention for authentication and for eloquent did they mention that we are suppose to implement these interface for us to be able to use Auth::attempt() method, my question now is how then do we (newbies) know what to implement and what not to implement, or what any of these interfaces even do.
This is simple. It's a laravel's requirement. The User model is generated by default for you. If you do not need to implement the interface's methods, just add them empty in your User class.
And of course, in your case, what to extend or implement will be shown as errors on startup. Reading them carefully can give you all the asnwers.
Also, if you want to use different User Authentication features, or extend the existing ones, you can look some info here in the docs

How to setup multiple authenticators for users

I'm writing an application in PHP using Yii. I'm trying to add the ability for users to be able to be authenticated differently.
My main question is what is the best way to go about it.
For example, I was thinking of doing something like so:
Have a table of Authenticators in a database that correlates to classes.
In the users table, have an authenticator id column that correlates to an authenticator.
This is about where I get stuck. I'm trying to be a Yii as possible here and use ActiveRecord. Each authenticator would need to know the users ID, so I'd have to pass that to the authenticator model (that stores the class name) and then find a way to pull the actual class, while passing the user to that as well.
All this seems a bit ... over kill.
Any guidance would be greatly appreciated.
Thanks!
Kyle
Just create your own descendant of CUserIdentity which implements Factory pattern. Sounds difficult, but I think there's no short answer at all.
You have all your answers in this topic: Authentication and Authorization.
i'm suggesting you to use rbac approach and the easiest way is to use right module.

PHP authentication library, how to build and configure it?

The Title may not be as clear but Il explain what's my problem.
Im building PHP MVC framework for my project. I know there are awsome PHP frameworks, but I like to code and Im doing this to learn more about PHP and MVC and other OOP patterns.
It works great, at least components I built so far.
I use PHP 5.3 and namespaces, so I can require/load classes based on their namespaces/names.
I built SPR-0 class loader class and it enables me to use other libraries that use SPR-0 "standard"/convention like Doctrine or Symfony2 components inside my framework. And all functionality of the framework itself, i call it Core, is writen as a component. So i have \Core\Controller\Controller() class or \Core\Router\Dispatcher() class or \Filesystem\FileManager() class. So I use them where I need them. And Core components enables me to add routes, detect them, call aproppriate controller/action etc... to build an MVC basicly.
And now I need Authentication modul to check if user is loged in on protected pages.
How do I setup that? The bigest problem is how do I tell Authentication Module what tables to use? Where to find usernames and where to find passwords? How do I configure Authentication module, so it knows where to look for username and password?
I could setup users table in database and never change it, and then instruct Authentication where to find stuff he needs. But what if on next project I would like to use different database design, and i would like to use email row instead of username?
Hope you understand whats bothering me...
The short question is how to setup Authentication class/module so you can configure it later to use other rows to fetch data from, and how flexible can that class can be, as far as configuration goes? Should I map some where in configuration that variable username maps to table users row username, so i can change it latter to email? How do you build flexible and configurable Auth library?
The question is long, so thanks for reading...
If I understand you correctly, you want to be able to choose different DB tables for Auth depending upon what project you're working in...
Well why don't you create a config file that gets 'read' by the framework first thing?
That's what other frameworks do I think. You provide host,dbname,user and so on... In your case you'd, in addition to that, write in the config what tables and fields to use for authentication/auhorization?

Syncing my knockoutjs models with my backend (PHP)

Has anyone implemented something similar?
The problem I have is the fact that we're not using REST. The current plan is the following:
Create a controller called sync($modelName, $action) and throw all requests at that.
Create an interface called "syncable" and force models to implement it.
How it works:
GET http://localhost/sync?modelName=User&action=update&first_name=Peeter
This will look for a model named UserModel that implements the syncable interface. If found, update its parameters and update(); to db.
The syncable interface is to enable per-record actions. E.g. "Only record owner can update this record" or "Only admin can delete this record".
I wrote a fully function REST API framework into symfony 1.4. It supports JSON and JSONP. I've open sourced it, so you're welcome to use it. We're using it in production with a lot of traffic, so it's pretty stable and we've had great feedback from the consumers. It's really flexible and very fast to write API methods. We also have a documentation page that allows you to make test queries. It's one of the best API docs I've seen.
https://github.com/homer6/blank_altumo
See this (below) for an example of an API controller. This contoller only shows GET, but PUT, POST and DELETE are fully implemented.
https://github.com/homer6/blank_altumo/blob/master/htdocs/project/apps/api/modules/system_event/actions/actions.class.php
If you need help getting it going, I'm willing to spend a few minutes to explain its design or get it working for you.
Hope that helps...
I had the same issue with an app I'm working on, so I implemented a ChangeTracker that subscribes to my observable properties, and tracks any changes made. Then, at any later point, I can call something like:
viewModel.changeTracker.commit();
which is responsible for massaging my change objects into a format that the server understands, and ships it off for processing.
Here is a little fiddle demonstrating the idea. http://jsfiddle.net/ggoforth/pCX8c/2/
Note: I've had a string of days where I've been working till 3am so there may be a better way of doing this, and I'm just to exhausted to realize it :)

Categories