{"id":15370108,"url":"https://github.com/danschultzer/coherence_assent","last_synced_at":"2025-04-15T13:52:20.086Z","repository":{"id":57484485,"uuid":"102149105","full_name":"danschultzer/coherence_assent","owner":"danschultzer","description":"UNMAINTAINED - Add multi provider login to your Coherence Phoenix website","archived":false,"fork":false,"pushed_at":"2019-03-07T02:00:16.000Z","size":121,"stargazers_count":27,"open_issues_count":0,"forks_count":6,"subscribers_count":3,"default_branch":"master","last_synced_at":"2025-03-28T20:46:11.637Z","etag":null,"topics":["basecamp","coherence","facebook","github","google-oauth2","oauth2","phoenix","twitter"],"latest_commit_sha":null,"homepage":"","language":"Elixir","has_issues":false,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"other","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/danschultzer.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-09-01T20:06:45.000Z","updated_at":"2024-07-18T06:08:56.000Z","dependencies_parsed_at":"2022-08-26T14:23:53.600Z","dependency_job_id":null,"html_url":"https://github.com/danschultzer/coherence_assent","commit_stats":null,"previous_names":[],"tags_count":11,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/danschultzer%2Fcoherence_assent","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/danschultzer%2Fcoherence_assent/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/danschultzer%2Fcoherence_assent/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/danschultzer%2Fcoherence_assent/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/danschultzer","download_url":"https://codeload.github.com/danschultzer/coherence_assent/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":249085474,"owners_count":21210267,"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":["basecamp","coherence","facebook","github","google-oauth2","oauth2","phoenix","twitter"],"created_at":"2024-10-01T13:39:57.412Z","updated_at":"2025-04-15T13:52:20.067Z","avatar_url":"https://github.com/danschultzer.png","language":"Elixir","funding_links":[],"categories":[],"sub_categories":[],"readme":"\u003e **WARNING: This library is no longer maintained. Please consider switching to [PowAssent](https://github.com/danschultzer/pow_assent) using [Pow](https://github.com/danschultzer/pow). Coherence is known to have serious security issues.**\n\n# CoherenceAssent\n\n[![Build Status](https://travis-ci.org/danschultzer/coherence_assent.svg?branch=master)](https://travis-ci.org/danschultzer/coherence_assent) [![hex.pm](http://img.shields.io/hexpm/v/coherence_assent.svg?style=flat)](https://hex.pm/packages/coherence_assent) [![hex.pm downloads](https://img.shields.io/hexpm/dt/coherence_assent.svg?style=flat)](https://hex.pm/packages/coherence_assent)\n\nUse Google, Github, Twitter, Facebook, Basecamp, VK or add your own strategy for authorization to your Coherence Phoenix app.\n\n## Features\n\n* Collects required login field if missing verified email from provider\n* Multiple providers can be used for accounts\n  * When removing auth: Validates user has password or another provider authentication\n* Github, Google, Twitter, Facebook, Basecamp and VK strategies included\n* Updates Coherence templates automatically\n* You can add your custom strategy with ease\n\n## Installation\n\n**Note:** This version requires Coherence `v0.5.2` and above. If you wish to use `v0.5.0`, please use the `v0.3.x` release(s). If you get dependency resolution failure with ecto when you install Coherence or coherence_assent, just run `mix deps.unlock ecto`.\n\nAdd CoherenceAssent to your list of dependencies in `mix.exs`:\n\n```elixir\ndef deps do\n  [\n    # ...\n    {:coherence_assent, \"~\u003e 0.4\"}\n    # ...\n  ]\nend\n```\n\nRun `mix deps.get` to install it.\n\n## Set up Coherence\n\nYou need to make sure the Coherence views and routes has been set up first. If this hasn't been done, follow the next steps.\n\nAdd all the Coherence files to your project:\n\n```bash\nmix coh.install --full --confirmable --invitable\n```\n\nUpdate routes:\n\n```elixir\n# lib/my_project_web/router.ex\n\ndefmodule MyProjectWeb.Router do\n  use MyProjectWeb, :router\n  use Coherence.Router                    # Add this\n\n  pipeline :browser do\n    plug :accepts, [\"html\"]\n    plug :fetch_session\n    plug :fetch_flash\n    plug :protect_from_forgery\n    plug :put_secure_browser_headers\n    plug Coherence.Authentication.Session # Add this\n  end\n\n  # Add this block\n  pipeline :protected do\n    plug :accepts, [\"html\"]\n    plug :fetch_session\n    plug :fetch_flash\n    plug :protect_from_forgery\n    plug :put_secure_browser_headers\n    plug Coherence.Authentication.Session, protected: true\n  end\n\n  # ...\n\n  # Add this block\n  scope \"/\" do\n    pipe_through :browser\n    coherence_routes()\n  end\n\n  # Add this block\n  scope \"/\" do\n    pipe_through :protected\n    coherence_routes :protected\n  end\n\n  # ...\nend\n```\n\n## Getting started\n\nRun to update all Coherence files:\n\n```bash\nmix coherence_assent.install\n```\n\nThe install script will attempt to update the following files that Coherence have installed:\n\n```text\nLIB_PATH/coherence/user.ex\nWEB_PATH/templates/coherence/registration/edit.html.eex\nWEB_PATH/templates/coherence/registration/new.html.eex\nWEB_PATH/templates/coherence/session/new.html.eex\nWEB_PATH/views/coherence/coherence_view_helpers.ex\nWEB_PATH/coherence_messages.ex\n```\n\nIf the files cannot be updated, install instructions will be printed instead. It's important that you update all files according to these instructions.\n\nSet up routes:\n\n```elixir\n# lib/my_project_web/router.ex\n\ndefmodule MyAppWeb.Router do\n  use MyAppWeb, :router\n  use Coherence.Router\n  use CoherenceAssent.Router  # Add this\n\n  # ...\n\n  scope \"/\" do\n    pipe_through [:browser]\n    coherence_routes()\n    coherence_assent_routes() # Add this\n  end\n\n  # ...\nend\n```\n\nThe following routes will now be available in your app:\n\n```text\ncoherence_assent_auth_path  GET             /auth/:provider              CoherenceAssent.AuthController :index\ncoherence_assent_auth_path  GET             /auth/:provider/callback     CoherenceAssent.AuthController :callback\ncoherence_assent_auth_path  DELETE          /auth/:provider              CoherenceAssent.AuthController :delete\ncoherence_assent_registration_path  GET     /auth/:provider/new          CoherenceAssent.RegistrationController :add_login_field\ncoherence_assent_registration_path  POST    /auth/:provider/create       CoherenceAssent.RegistrationController :create\n```\n\nRemember to run the new migrations: `mix ecto.setup` (or `mix ecto.migrate`)\n\n## Setting up a provider\n\nStrategies for Twitter, Facebook, Google, Github and Basecamp are included. We'll go through how to set up the Github strategy.\n\nFirst, register [a new app on Github](https://github.com/settings/applications/new) and add `http://localhost:4000/auth/github/callback` as callback URL. Then add the following to `config/config.exs` and add the client id and client secret:\n\n```elixir\nconfig :coherence_assent, :providers,\n       [\n         github: [\n           client_id: \"REPLACE_WITH_CLIENT_ID\",\n           client_secret: \"REPLACE_WITH_CLIENT_SECRET\",\n           strategy: CoherenceAssent.Strategy.Github\n        ]\n      ]\n```\n\nNow start (or restart) your Phoenix app, and visit `http://localhost:4000/registrations/new`. You'll see a \"Sign in with Github\" link.\n\n## Custom provider\n\nYou can add your own strategy. Here's an example of an OAuth 2.0 implementation:\n\n```elixir\ndefmodule TestProvider do\n  alias CoherenceAssent.Strategy.Helpers\n  alias CoherenceAssent.Strategy.OAuth2, as: OAuth2Helper\n\n  def authorize_url(conn, config) do\n    OAuth2Helper.authorize_url(conn, set_config(config))\n  end\n\n  def callback(conn, config, params) do\n    config = set_config(config)\n\n    conn\n    |\u003e OAuth2Helper.callback(config, params)\n    |\u003e normalize()\n  end\n\n  defp set_config(config) do\n    [\n      site: \"http://localhost:4000/\",\n      authorize_url: \"http://localhost:4000/oauth/authorize\",\n      token_url: \"http://localhost:4000/oauth/access_token\",\n      user_url: \"/user\",\n      authorization_params: [scope: \"email profile\"]\n    ]\n    |\u003e Keyword.merge(config)\n    |\u003e Keyword.put(:strategy, OAuth2.Strategy.AuthCode)\n  end\n\n  defp normalize({:ok, %{conn: conn, client: client, user: user}}) do\n    user = %{\"uid\"        =\u003e user[\"sub\"],\n             \"name\"       =\u003e user[\"name\"],\n             \"email\"      =\u003e user[\"email\"]}\n           |\u003e Helpers.prune\n\n    {:ok, %{conn: conn, client: client, user: user}}\n  end\n  defp normalize({:error, error}), do: {:error, error}\nend\n```\n\n## Security concerns\n\nAll sessions created through `CoherenceAssent` provider authentication are temporary, and doesn't use the `rememberable` configuration in Coherence. However, it's a good idea to do some housekeeping in your app and making sure that you have the level of security as warranted by the scope of your app. This may include requiring users to reauthenticate before viewing or editing their user details.\n\n## LICENSE\n\n(The MIT License)\n\nCopyright (c) 2017 Dan Schultzer \u0026 the Contributors Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the 'Software'), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:\n\nThe above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.\n\nTHE SOFTWARE IS PROVIDED 'AS IS', WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fdanschultzer%2Fcoherence_assent","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fdanschultzer%2Fcoherence_assent","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fdanschultzer%2Fcoherence_assent/lists"}