{"id":24529253,"url":"https://github.com/opencomponents/oc-plugin-authenticate","last_synced_at":"2025-03-15T17:46:02.592Z","repository":{"id":57313219,"uuid":"139009279","full_name":"opencomponents/oc-plugin-authenticate","owner":"opencomponents","description":"A plugin to enable token based authentication for your OC components.","archived":false,"fork":false,"pushed_at":"2018-06-29T14:03:59.000Z","size":11,"stargazers_count":1,"open_issues_count":0,"forks_count":1,"subscribers_count":16,"default_branch":"master","last_synced_at":"2025-02-22T17:42:44.434Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":null,"language":"JavaScript","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/opencomponents.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":"2018-06-28T11:30:11.000Z","updated_at":"2018-09-25T02:31:17.000Z","dependencies_parsed_at":"2022-09-20T23:10:23.479Z","dependency_job_id":null,"html_url":"https://github.com/opencomponents/oc-plugin-authenticate","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/opencomponents%2Foc-plugin-authenticate","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/opencomponents%2Foc-plugin-authenticate/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/opencomponents%2Foc-plugin-authenticate/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/opencomponents%2Foc-plugin-authenticate/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/opencomponents","download_url":"https://codeload.github.com/opencomponents/oc-plugin-authenticate/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":243769949,"owners_count":20345215,"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":[],"created_at":"2025-01-22T07:35:38.892Z","updated_at":"2025-03-15T17:46:02.536Z","avatar_url":"https://github.com/opencomponents.png","language":"JavaScript","readme":"# oc-plugin-authenticate\noc-plugin-authenticate allows any OC component to authenticate requests.\n\n## Authentication\nAn OC appication using this plugin may authenticate any request to help control application flow and protect sensitive data.\n\nUsage:\n```js\nmodule.exports.data = (context, callback) =\u003e {\n  context.plugins.authenticate(context, (err, {user, access_token}) =\u003e {\n    if (err) {\n      const errorMessage = 'unable to authenticate user';\n      return callback(errorMessage);\n    }\n\n    callback(null, {\n      access_token,\n      username: user.username\n    })\n  });\n};\n```\nAfter authenticating, you will receive either an error or a value using the callback pattern. The value will contain a `user` object, and a `token` string.\n\n- The `user` object will contain any claims or details provided within your authentication token.\n\n- The `token` string will be the authentication token provided in the original request and can be used to ensure further interactions with your OC component (eg. via AJAX calls using `getData`) are authenticated (see: [Persisting authentication](#Persisting-authentication)).\n\nThe authenticate method also has a few overloads which allows you to influence the authenticate algorithm if necessary.\n\n```js\ncontext.plugins.authenticate(context, strategy, callback);\ncontext.plugins.authenticate(context, options, callback);\ncontext.plugins.authenticate(context, strategy, options, callback);\n```\n\n`strategy` : `string` Allows you to specify what strategy to use when authenticating. The value must refer to one of the strategies provided when the plugin was registered within the oc-registry.\n\n`options` : `object` Will override something or another UPDATE THIS PART PLEASE!\n\n### Persisting authentication\n\nWhen making `getData` calls within your component, sending headers is not possible by design as it causes the browser to make a [pre-flight request](https://developer.mozilla.org/en-US/docs/Glossary/Preflight_request). Therefore, you must provide the token as a simple oc parameter to ensure your application can authenticate your XHR request.\n\n**We recommend that you reserve and use the `access_token` parameter to send the access_token because most `oc-authentication-strategy` implementations will expect this parameter by default.**\n\nReact Template example:\n```js\n  class MyComponent extends React.Component {\n    constructor(props) {\n      super(props);\n    }\n\n    doSomething(data) {\n      const { access_token } = this.props;\n      const params = {\n        ...data,\n\n        // we use access_token to ensure\n        // that we can authenticate\n        // our requests.\n        access_token\n      };\n\n      this.props.getData(params, (err, data) =\u003e {\n        this.setState({ data });\n      });\n    }\n\n    render() {\n      return \u003cbutton onClick={() =\u003e this.doSomething({ name: 'bob' })}\u003eGO!\u003c/button\u003e\n    }\n  }\n```\n\n## Registry setup\nFor more information about integrating OC plugins [click here](https://github.com/opencomponents/oc/wiki/Registry#plugins).\n\nWhen registering, the plugin must provide at least one `strategy` and must specify the `defaultStrategy`. Optionally, you may provide default `options` that will be provided to your strategy function.\n\n```js\nconst configuration = { ... };\nconst registry = new oc.Registry(configuration);\nconst twitterAuth = require('some-twitter-oc-authentication-strategy');\nconst internalAuth = require('some-internal-oc-authentication-strategy');\n\nregistry.register(\n  {\n    name: 'authenticate',\n    register: require('oc-authenticate'),\n    options: {\n      strategies: {\n        twitter: {\n          strategy: twitterAuth,\n        }\n        internal: {\n          strategy: internalAuth\n          options: { ... }\n        }\n      },\n      defaultStrategy: 'twitter'\n    }\n  }\n);\n\nregistry.start(callback);\n```\n\n## Authentication Strategies\n[Creating an authentication strategy](docs/CREATING_STRATEGIES.md).","funding_links":[],"categories":[],"sub_categories":[],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fopencomponents%2Foc-plugin-authenticate","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fopencomponents%2Foc-plugin-authenticate","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fopencomponents%2Foc-plugin-authenticate/lists"}