{"id":16754936,"url":"https://github.com/grimzy/security-json-service-provider","last_synced_at":"2025-03-16T06:14:35.624Z","repository":{"id":62512708,"uuid":"82635989","full_name":"grimzy/security-json-service-provider","owner":"grimzy","description":"Silex Security JSON Service Provider","archived":false,"fork":false,"pushed_at":"2017-02-21T19:57:37.000Z","size":43,"stargazers_count":0,"open_issues_count":0,"forks_count":0,"subscribers_count":3,"default_branch":"master","last_synced_at":"2025-01-22T18:29:00.681Z","etag":null,"topics":["authentication","php","silex","silex-security"],"latest_commit_sha":null,"homepage":"","language":"PHP","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/grimzy.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2017-02-21T04:29:21.000Z","updated_at":"2017-02-21T05:46:57.000Z","dependencies_parsed_at":"2022-11-02T13:16:48.418Z","dependency_job_id":null,"html_url":"https://github.com/grimzy/security-json-service-provider","commit_stats":null,"previous_names":[],"tags_count":1,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/grimzy%2Fsecurity-json-service-provider","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/grimzy%2Fsecurity-json-service-provider/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/grimzy%2Fsecurity-json-service-provider/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/grimzy%2Fsecurity-json-service-provider/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/grimzy","download_url":"https://codeload.github.com/grimzy/security-json-service-provider/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":243830955,"owners_count":20354855,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["authentication","php","silex","silex-security"],"created_at":"2024-10-13T03:06:25.419Z","updated_at":"2025-03-16T06:14:35.604Z","avatar_url":"https://github.com/grimzy.png","language":"PHP","funding_links":[],"categories":[],"sub_categories":[],"readme":"# Silex Security JSON Service Provider\n\n[![Build Status](https://img.shields.io/travis/ARCANEDEV/LogViewer.svg?style=flat-square)](https://travis-ci.org/grimzy/security-json-service-provider)\n[![Packagist](https://img.shields.io/packagist/v/grimzy/security-json-service-provider.svg?style=flat-square)](https://packagist.org/packages/grimzy/security-json-service-provider)\n[![Packagist](https://img.shields.io/packagist/dt/grimzy/security-json-service-provider.svg?style=flat-square)](https://packagist.org/packages/grimzy/security-json-service-provider)\n[![Packagist Pre Release](https://img.shields.io/packagist/vpre/grimzy/security-json-service-provider.svg?style=flat-square)](https://packagist.org/packages/grimzy/security-json-service-provider)\n[![license](https://img.shields.io/github/license/mashape/apistatus.svg?style=flat-square)](LICENSE)\n\n\n\nThis Security factory provides a cookie-less replacement for `form_login` which cannot be used .\n\nSince they rely on cookies, the `switch_user` and `logout` config options are not supported with this Security factory.\n\n**Security advisory:** Although you are not forced to, it is highly advised to use HTTPS.\n\n## Installation\n\nUsing command line:\n\n```shell\ncomposer require grimzy/security-json-service-provider:1.0^\n```\n\nOr adding to composer.json:\n\n```\n\"grimzy/security-json-service-provider:1.0^\"\n```\n\n## Usage\n\nConfigure firewalls:\n\n```php\n$app['security.firewalls'] = [\n  'login' =\u003e [\n    'pattern' =\u003e '^/api/login',\n    'anonymous' =\u003e true,\n    'stateless' =\u003e true,\n    'json' =\u003e [\n      // Default configuration\n      'username_parameter' =\u003e 'username',\n      'password_parameter' =\u003e 'password',\n      'post_only' =\u003e true,\n      'json_only' =\u003e true\n    ]\n  ],\n\n  'secured' =\u003e [\n    'pattern' =\u003e '^.*$',\n    'stateless' =\u003e true,\n    'token' =\u003e true\t\n  ],\n];\n```\n\nAdd a users provider:\n\n```php\n$app['users'] = function () use ($app) {\n  return new InMemoryUserProvider([\n    'admin' =\u003e [\n      'roles' =\u003e ['ROLE_ADMIN'],\n      'password' =\u003e '5FZ2Z8QIkA7UTZ4BYkoC+GsReLf569mSKDsfods6LYQ8t+a8EW9oaircfMpmaLbPBh4FOBiiFyLfuZmTSUwzZg==',\t// foo\n      'enabled' =\u003e true\n    ],\n  ]);\n};\n```\n\nExample configuration:\n\n```php\n$app['security.firewalls' =\u003e [\n  'login' =\u003e [\n    'pattern' =\u003e '^/api/login',\n    'anonymous' =\u003e true,\n    'stateless' =\u003e true,\n    'json' =\u003e [\n      // Default configuration\n      'username_parameter' =\u003e 'username',\n      'password_parameter' =\u003e 'password',\n      'post_only' =\u003e true,\n      'json_only' =\u003e true\n    ]\n  ],\n\n  'secured' =\u003e [\n    'pattern' =\u003e '^.*$',\n    'stateless' =\u003e true,\n    'token' =\u003e true\n  ],\n]];\n```\n\nRegister the service providers:\n\n```php\n$app-\u003eregister(new Silex\\Provider\\SecurityServiceProvider());\n$app-\u003eregister(new Silex\\Provider\\SecurityJsonServiceProvider());\n```\n\nDefine a route (**only accessible after successful authentication**):\n\n```php\nuse Symfony\\Component\\HttpFoundation\\Request;\nuse Symfony\\Component\\HttpFoundation\\JsonResponse;\n\n$app-\u003epost('/api/login', function(Request $request) use ($app) {\n  $user = $app['user'];\t// Logged in user\n  \n  $token = $app['some.token_encoder']-\u003eencode($user);\n  \n  return new JsonResponse([\n    'token' =\u003e $token\n  ]);\n};\n```\n**Note:** if `post_only` is `false`, you can use `$app-\u003eget()` instead of `$app-\u003epost` when defining your route.\n\n## Override entry point\n\nCreate a new class implementing `Symfony\\Component\\Security\\Http\\EntryPoint\\AuthenticationEntryPointInterface`:\n\n```php\nuse Symfony\\Component\\HttpFoundation\\Request;\nuse Symfony\\Component\\HttpFoundation\\Response;\nuse Symfony\\Component\\Security\\Core\\Exception\\AuthenticationException;\nuse Symfony\\Component\\Security\\Http\\EntryPoint\\AuthenticationEntryPointInterface;\n\nclass GandalfAuthenticationEntryPoint implements AuthenticationEntryPointInterface\n{\n    /**\n     * {@inheritdoc}\n     */\n    public function start(Request $request, AuthenticationException $authException = null)\n    {\n        return new Response('You shall not pass!', Response::HTTP_UNAUTHORIZED);\n    }\n}\n```\n\nReplace the packaged JsonAuthenticationEntrypoint with the created one:\n\n```php\n$app-\u003eregister(new Silex\\Provider\\SecurityJsonServiceProvider());\n\n// after registering the provider\n$app['security.entry_point.json'] = function () use ($app) {\n    return new GandalfAuthenticationEntryPoint();\n};\n```","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fgrimzy%2Fsecurity-json-service-provider","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fgrimzy%2Fsecurity-json-service-provider","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fgrimzy%2Fsecurity-json-service-provider/lists"}