{"id":21884628,"url":"https://github.com/onehilltech/ember-cli-gatekeeper","last_synced_at":"2025-04-15T07:19:33.543Z","repository":{"id":37677591,"uuid":"78374417","full_name":"onehilltech/ember-cli-gatekeeper","owner":"onehilltech","description":"EmberJS add-on for Gatekeeper","archived":false,"fork":false,"pushed_at":"2024-04-11T00:36:51.000Z","size":7846,"stargazers_count":2,"open_issues_count":1,"forks_count":1,"subscribers_count":1,"default_branch":"master","last_synced_at":"2025-03-28T17:47:18.270Z","etag":null,"topics":["ember","ember-addon","ember-cli","gatekeeper"],"latest_commit_sha":null,"homepage":"","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/onehilltech.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":"CONTRIBUTING.md","funding":null,"license":"LICENSE.md","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2017-01-08T22:23:17.000Z","updated_at":"2024-04-06T17:55:22.000Z","dependencies_parsed_at":"2024-04-11T01:45:13.895Z","dependency_job_id":null,"html_url":"https://github.com/onehilltech/ember-cli-gatekeeper","commit_stats":null,"previous_names":[],"tags_count":431,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/onehilltech%2Fember-cli-gatekeeper","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/onehilltech%2Fember-cli-gatekeeper/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/onehilltech%2Fember-cli-gatekeeper/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/onehilltech%2Fember-cli-gatekeeper/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/onehilltech","download_url":"https://codeload.github.com/onehilltech/ember-cli-gatekeeper/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":248882777,"owners_count":21177105,"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":["ember","ember-addon","ember-cli","gatekeeper"],"created_at":"2024-11-28T10:14:59.573Z","updated_at":"2025-04-15T07:19:33.528Z","avatar_url":"https://github.com/onehilltech.png","language":"JavaScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"ember-cli-gatekeeper\n====================\n\nEmberJS add-on for [blueprint-gatekeeper](https://github.com/onehilltech/blueprint-gatekeeper)\n\n[![npm version](https://img.shields.io/npm/v/ember-cli-gatekeeper.svg?maxAge=2592000)](https://www.npmjs.com/package/ember-cli-gatekeeper)\n[![Dependencies](https://david-dm.org/onehilltech/ember-cli-gatekeeper.svg)](https://david-dm.org/onehilltech/ember-cli-gatekeeper)\n\n\n## Compatibility\n\n* Ember.js v4.4 or above\n* Ember CLI v4.4 or above\n* Node.js v14 or above\n\nInstallation\n--------------\n\n    ember install ember-cli-gatekeeper\n    \nGetting Started\n----------------\n\n## Defining the configuration\n\nUpdate the `ENV` variable in `config/environment.js` with the required\nconfiguration values:\n\n| Name  | Description | Required | Default Value |\n|-------|-------------|----------|---------------|\n| gatekeeper.baseUrl | Location of blueprint-gatekeeper | Yes | |\n| gatekeeper.startRoute | Default route name, or url, to transition to after login | | index |\n| gatekeeper.signInRoute | Name of the sign in route | | sign-in |      \n| gatekeeper.tokenOptions.client_id | Client id | Yes | |\n| gatekeeper.tokenOptions.client_secret | Client secret | | |\n\nThe client secret should only be used if the web application is installed in\na trusted environment, such as a mobile application via [ember-cordova](http://embercordova.com/).\n\nHere is an example `config/environment.js` with the Gatekeeper configuration:\n\n```javascript 1.6\nlet ENV = {\n  // ...\n  \n  EmberENV: {\n    FEATURES: {\n    // This must be enabled for account adapter to work.\n    'ds-improved-ajax': true\n    }\n    \n    // ...\n  },\n  \n  gatekeeper: {\n    baseUrl: 'https://mydomain.com/gatekeeper',\n\n    tokenOptions: {      \n      client_id: '59ee923e1fd71c2ae68ade62',\n      client_secret: '1234567890'\n    }\n  }\n}\n```\n\n## Protecting application routes\n\nProtected application routes are routes that require the user to be signed in\nto access. Creating protected application route is very simple.\n \nFirst, create the route using [ember-cli](https://ember-cli.com/).\n\n    ember g route [name]\n    \nThen, import the `authenticated` decorator from `ember-cli-gatekeeper` and apply it\nto the route.\n\n```javascript\n// app/routes/comments.js\n\nimport Route from '@ember/routing/route';\nimport { authenticated } from 'ember-cli-gatekeeper';\n\n@authenticated\nexport default class CommentsRoute extends Route {\n  async model () {\n    // Get all comments for the current user.\n    return this.store.query ('comment', { user: this.session.currentUser.id });\n  }\n};\n```\n\nThe [session](https://github.com/onehilltech/ember-cli-gatekeeper/blob/master/addon/services/session.js) \nservice is injected into all routes. This service can be used to access the\n`currentUser` property, which gives you access to the \n[account model](https://github.com/onehilltech/ember-cli-gatekeeper/blob/master/addon/models/account.js)\n(less the password) for the signed in user.\n\n\u003e When this route is accessed and the user is not signed in, the user will\n\u003e be transitioned to the `sign-in` route (see [Configuration](#defining-the-configuration)). After\n\u003e the user signs in, the user will be transitioned back to the original route.\n\n\n## Making authorized requests\n\n[ember-data](https://github.com/emberjs/data) uses data models to access resources on \na remote server. When using Gatekeeper, the routes for accessing these resources is\nprotected via an authorization token. To get this authorization token into each\n[ember-data](https://github.com/emberjs/data) request, you must use the `@bearer`\ndecorator.\n\n```javascript\n// app/adapters/application.js\nimport RESTAdapter from \"@ember-data/adapter/rest\";\nimport {bearer} from 'ember-cli-gatekeeper';\n\n@bearer\nexport default class ApplicationAdapter extends RESTAdapter {\n  \n}\n```\n\nYou can then continue [configuring the adapter](https://emberjs.com/api/ember-data/3.3/classes/DS.RESTAdapter) \nas normal.\n\n## Signing in a user\n\nTo sign in a user, you need a route with a form that collects the user's username\nand password. The Gatekeeper add-on provides a component/form that can be used to sign-in \na user.\n\n```handlebars\n\u003cGatekeeperSignIn /\u003e\n```\n\nThis component needs to be added to your sign-in route. When the user has signed in \nsuccessfully, the component will automatically route the user to either the\nstart route defined in the configuration, or the route originally accessed when\nthe user was not authenticated. \n\n### Using reCAPTCHA\n\nGatekeeper uses different public/private key verification schemes to ensure that robots are \nnot accessing the system. When developing a web application, it is not save \nto place a secret in an EmberJS application because it will be accessible to site visitors.\nWe therefore recommend you use a reCAPTCHA service, such as Google reCAPTCHA, to verify users\nare not robots.\n\nGatekeeper provides out-of-the-box support for Google reCAPTCHA via the \n[ember-cli-google-recaptcha](https://github.com/onehilltech/ember-cli-google-recaptcha) add-on.\nFirst, you have to do is add your `siteKey` to `config/environment.js`:\n\n```javascript\nlet ENV = {\n  // ...\n  \n  'ember-cli-google': {\n    recaptcha: {\n      siteKey: 'This is where my siteKey goes'\n    }\n  }\n};\n```\n\nThe add-on will automatically detect the presence of the `siteKey`, and enable Google reCAPTCHA\nin the default login form. Next, you replace the standard sign in component with the \nreCAPTCHA sign in component.\n\n```handlebars\n\u003cGatekeeperSignInWithRecaptcha recaptcha=\"v2\" /\u003e\n```\n\n\u003e Set `recaptcha=\"invisible\"` to use invisible reCAPTCHA.\n\n## Signing out a user\n\nA signed in user can be signed out from any where in the application as long as you\nhave access to the `session` service.\n\n\u003e The `session` service is injected into all routes and controllers.\n\n```javascript\n// app/controllers/index.js\n\nimport Controller from '@ember/controller';\nimport { action } from '@ember/object';\n\nexport default class IndexController extends Controller {\n  @action\n  async signOut () {\n    await this.session.signOut ();\n    this.replaceRoute ('sign-in');\n  }\n}\n```\n\n## Allowing users to create accounts\n\nThe Gatekeeper add-on also provides a default form for creating a new account. You use\nit in a similar manner as signing in a user. First, add the sign up form to the route for\nsigning up a user, and configure the form to your needs.\n\n```handlebars\n\u003cGatekeeperSignUp /\u003e\n```\n\n\u003e The Gatekeeper add-on also has sign up components that supports reCAPTCHA.\n\n\u003e The client registered with the server must have the `gatekeeper.account.create` scope.\n\u003e Otherwise, the client will not be authorized to create the account.\n\n### Manually creating an account\n\nWe use the `account` model to create user accounts. We assume that you have\ncreated a template to gather the `username`, `password`, and `email address`\nfrom the user and have a controller action to that creates the account:\n\n```javascript\nimport Controller from '@ember/controller';\nimport { action } from '@ember/object';\n\nexport default class SignUpController extends Controller {\n  @action\n  async createAccount () {\n    const account = this.store.createRecord ('account', {username: this.username, password: this.password, email: this.email});\n    const adapterOptions = {signIn: true};\n      \n    await account.save ({adapterOptions});\n\n    // You can transition to a protected application route\n  }\n}\n```\n\nThe `save()` method takes an optional `adapterOptions` property that allows you to \nsign in the user when the account is created. The advantage of doing this it that \nit allows you to transition to a protected application route after account creation,\nor access [protected data](#accessing-protected-data) as part of the creation process.\nOtherwise, the user will have to sign in after creating the account to access a\nprotected application route.\n\nHappy Coding!\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fonehilltech%2Fember-cli-gatekeeper","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fonehilltech%2Fember-cli-gatekeeper","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fonehilltech%2Fember-cli-gatekeeper/lists"}