{"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] [BC BREAK] 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":10,"closed_issues":33,"state":"open","created_at":"2014-04-05T09:18:57Z","updated_at":"2015-02-01T17:51:00Z","due_on":null,"closed_at":null},"comments":10,"created_at":"2015-01-16T04:16:01Z","updated_at":"2015-02-01T20:03:28Z","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### V2\r\n\r\n - AdapterChain now triggers some events:\r\n    - attach\r\n    - authenticate.pre\r\n    - authenticate.success\r\n    - authenticate.failure\r\n - Added event listener to regenerate SID on `authenticate.pre` when Session storage is being used \r\n\r\n### V1\r\n\r\n - Rewrote the `AdapterChain` functionality.\r\n   - Now just a proxy to an internalized priority list of standard Authentication adapters.\r\n - Removed knowledge of Storage from adapters, as storage is handled by AuthenticationService.\r\n - TODOs / notes\r\n   - AdapterChain no longer triggers any events.  May be a good idea to put it back in. \r\n   - Ability to perform tasks on logout from the adapter has been removed.  Is this something people use?\r\n   - Throw an exception ([here](554/files#diff-5a0a2be486dee5dc09d7bbf7044831d1R44)) if there are no registered adapters?\r\n\r\n### V0\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.~~ _Done_\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?)~~ Added as an event listener automatically when Session storage is in use.\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~~?  We could autoregister an event listener on `authenticate.success` to handle this ([Prototype here](https://github.com/adamlundrigan/ZfcUser/commit/98fbc53733fc5ae7108e082045361950c80e7ba8)). \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.~~ _Done_\r\n - ~~Use [Zend\\Authentication\\Adapter\\DbTable\\CallbackCheckAdapter](https://github.com/zendframework/zf2/blob/master/library/Zend/Authentication/Adapter/DbTable/CallbackCheckAdapter.php)?~~ _Mapper adapter is now sufficiently simplified to negate this._"},"comment":{"url":"https://api.github.com/repos/ZF-Commons/ZfcUser/issues/comments/72381312","html_url":"https://github.com/ZF-Commons/ZfcUser/pull/554#issuecomment-72381312","issue_url":"https://api.github.com/repos/ZF-Commons/ZfcUser/issues/554","id":72381312,"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-02-01T20:03:28Z","updated_at":"2015-02-01T20:03:28Z","body":"I'm going to look through code now and drop comments, haven't tested yet though."}}