{"action":"created","issue":{"url":"https://api.github.com/repos/ZF-Commons/ZfcUser/issues/554","labels_url":"https://api.github.com/repos/ZF-Commons/ZfcUser/issues/554/labels{/name}","comments_url":"https://api.github.com/repos/ZF-Commons/ZfcUser/issues/554/comments","events_url":"https://api.github.com/repos/ZF-Commons/ZfcUser/issues/554/events","html_url":"https://github.com/ZF-Commons/ZfcUser/pull/554","id":54538263,"number":554,"title":"[WIP] [RFC] Refactor of authentication layer","user":{"login":"adamlundrigan","id":527329,"avatar_url":"https://avatars.githubusercontent.com/u/527329?v=3","gravatar_id":"","url":"https://api.github.com/users/adamlundrigan","html_url":"https://github.com/adamlundrigan","followers_url":"https://api.github.com/users/adamlundrigan/followers","following_url":"https://api.github.com/users/adamlundrigan/following{/other_user}","gists_url":"https://api.github.com/users/adamlundrigan/gists{/gist_id}","starred_url":"https://api.github.com/users/adamlundrigan/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/adamlundrigan/subscriptions","organizations_url":"https://api.github.com/users/adamlundrigan/orgs","repos_url":"https://api.github.com/users/adamlundrigan/repos","events_url":"https://api.github.com/users/adamlundrigan/events{/privacy}","received_events_url":"https://api.github.com/users/adamlundrigan/received_events","type":"User","site_admin":false},"labels":[{"url":"https://api.github.com/repos/ZF-Commons/ZfcUser/labels/Enhancement","name":"Enhancement","color":"207de5"},{"url":"https://api.github.com/repos/ZF-Commons/ZfcUser/labels/Refactoring","name":"Refactoring","color":"5319e7"}],"state":"open","locked":false,"assignee":null,"milestone":{"url":"https://api.github.com/repos/ZF-Commons/ZfcUser/milestones/2","labels_url":"https://api.github.com/repos/ZF-Commons/ZfcUser/milestones/2/labels","id":621116,"number":2,"title":"2.0.0","description":"","creator":{"login":"Danielss89","id":632956,"avatar_url":"https://avatars.githubusercontent.com/u/632956?v=3","gravatar_id":"","url":"https://api.github.com/users/Danielss89","html_url":"https://github.com/Danielss89","followers_url":"https://api.github.com/users/Danielss89/followers","following_url":"https://api.github.com/users/Danielss89/following{/other_user}","gists_url":"https://api.github.com/users/Danielss89/gists{/gist_id}","starred_url":"https://api.github.com/users/Danielss89/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/Danielss89/subscriptions","organizations_url":"https://api.github.com/users/Danielss89/orgs","repos_url":"https://api.github.com/users/Danielss89/repos","events_url":"https://api.github.com/users/Danielss89/events{/privacy}","received_events_url":"https://api.github.com/users/Danielss89/received_events","type":"User","site_admin":false},"open_issues":9,"closed_issues":32,"state":"open","created_at":"2014-04-05T09:18:57Z","updated_at":"2015-01-16T07:32:44Z","due_on":null,"closed_at":null},"comments":2,"created_at":"2015-01-16T04:16:01Z","updated_at":"2015-01-16T21:36:29Z","closed_at":null,"pull_request":{"url":"https://api.github.com/repos/ZF-Commons/ZfcUser/pulls/554","html_url":"https://github.com/ZF-Commons/ZfcUser/pull/554","diff_url":"https://github.com/ZF-Commons/ZfcUser/pull/554.diff","patch_url":"https://github.com/ZF-Commons/ZfcUser/pull/554.patch"},"body":"## Why?\r\nIn a recent project I aimed to build a ZfcUser-based app to be used in both console and API (Apigility) contexts, and the authentication layer in it's current form is not well suited for either.  \r\n\r\n - `AuthenticationChainEvent` internalizes a copy of the Request object \r\n - `Db` auth adapter uses `getPost` to pull user input from `AuthenticationChainEvent::$request` [#541]\r\n - `Db` auth adapter assumes it's working with a PHP session [#513 #518] \r\n - `Db` auth adapter assumes it's working with Bcrypt (not as big a deal as the others)\r\n\r\nAll of the above necessitated a partial rewrite of the `Db` auth adapter for our particular use case.  As a more permanent fix I'd like to suggest the PR'd modifications to the authentication layer for ZfcUser 2.x. \r\n\r\nThis code is in no way finished and still needs additional work (see TODO below).  Please dissect at your leisure and insult/nitpick/praise/rewrite to your heart's content ;) \r\n\r\n## Overview of changes\r\n\r\n - Modified `AuthenticationChainEvent` to store identity and credential, instead of request\r\n - Renamed storage and adapter classes from `Db` to `Mapper`, a more apt description of their inner workings.\r\n - Adapter now takes a mapper, a mapper method name, and a credential processor (`Zend\\Crypt\\Password\\PasswordInterface`)\r\n - Split the SM factory into two: `MapperUsernameFactory` and `MapperEmailFactory`\r\n - Storage now takes a mapper and a backing storage object (session by default)\r\n - Rejigged the service manager initialization for storage and adapter\r\n  - Both now have factories instead of implementing `ServiceManagerAwareInterface`\r\n  - Added generic service aliases for both to make overriding the concrete implementation easier\r\n\r\n## TODO\r\n - Does adapter need to know about storage?  I'm leaning towards moving the read from / write to storage somewhere else...but it's not really of top necessity now that storage is decoupled from session.\r\n - Regenerating the session ID was inbuilt to `Db` auth adapter.  I've removed it, but it needs to be implemented somewhere else that makes more sense (event listener attached by session storage factory?)\r\n - Persisting the user's password hash if it has changed was removed from `Db` auth adapter.  Is this something that's necessary, and if so where should we trigger it?\r\n - Fix the tests.  The exposed behaviours of the authentication layer haven't changed, but the method of instantiation and list of collaborators has changed for a number of classes. \r\n"},"comment":{"url":"https://api.github.com/repos/ZF-Commons/ZfcUser/issues/comments/70326232","html_url":"https://github.com/ZF-Commons/ZfcUser/pull/554#issuecomment-70326232","issue_url":"https://api.github.com/repos/ZF-Commons/ZfcUser/issues/554","id":70326232,"user":{"login":"Danielss89","id":632956,"avatar_url":"https://avatars.githubusercontent.com/u/632956?v=3","gravatar_id":"","url":"https://api.github.com/users/Danielss89","html_url":"https://github.com/Danielss89","followers_url":"https://api.github.com/users/Danielss89/followers","following_url":"https://api.github.com/users/Danielss89/following{/other_user}","gists_url":"https://api.github.com/users/Danielss89/gists{/gist_id}","starred_url":"https://api.github.com/users/Danielss89/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/Danielss89/subscriptions","organizations_url":"https://api.github.com/users/Danielss89/orgs","repos_url":"https://api.github.com/users/Danielss89/repos","events_url":"https://api.github.com/users/Danielss89/events{/privacy}","received_events_url":"https://api.github.com/users/Danielss89/received_events","type":"User","site_admin":false},"created_at":"2015-01-16T21:36:29Z","updated_at":"2015-01-16T21:36:29Z","body":"Awesome that you started refactor of the authentication system, i had that on my todo list too.\r\nI want to move away from the way it is done now, by events, as it's a totally wrong usage of how events should be used."}}