Skip to content

aatauil/mu-node-authentication-service

Repository files navigation

mu-node-authentication

mu-node-authentication-service

Authentication service for Semantic.Works

license: MIT docker-publish


Functionality:

  • ✍️ Registration
  • 👨‍🦰 Login
  • 🔑 Change password

Core Features:

  • 📃 JSON:API compliant
  • ⚙️ Customizable
  • ⭕ Semantic.works ready
  • 💻 Written 100% in Javascript

📖 Documentation

Description

This service makes it easy to quickly setup an application where users can register and login to their account. It is made with the semantic.works framework in mind. The service is kept simple so you can easily extend it with your own functionality like 2FA. Tutorials on how to add add certain functionality will be made available in this repo's wiki in the near future.

Getting Started

Add to your semantic.works stack

  • Add the following service to your docker-compose.yml file:
  authentication: 
    image: aatauil/mu-node-authentication-service
    labels:
      - "logging=true"
    restart: always
    logging: *default-logging
  • Add the following routes to your config/dispatcher/dispatcher.ex file:
  post "/accounts/*path" do
    Proxy.forward conn, path, "http://authentication/accounts/" 
  end

  delete "/accounts/current/*path" do
    Proxy.forward conn, path, "http://authentication/accounts/current/" 
  end

  patch "/accounts/current/changePassword/*path" do
    Proxy.forward conn, path, "http://authentication/accounts/current/changePassword/" 
  end

  match "/sessions/*path" do
    Proxy.forward conn, path, "http://authentication/sessions/" 
  end
  • Create a file called master-account-domain.lisp under config/resources and paste the following code into the file:
    (define-resource account ()
      :class (s-prefix "foaf:OnlineAccount")
      :properties `((:email :string ,(s-prefix "account:email")))
      :resource-base (s-url "http://mu.semte.ch/vocabularies/accounts/")
      :on-path "accounts")
  • In your config/resources/repository.lisp file, add the following prefixes
   (add-prefix "foaf" "http://xmlns.com/foaf/0.1/")
   (add-prefix "account" "http://mu.semte.ch/vocabularies/account/")
  • Finally add the following line to your config/resources/domain.lisp file
    (read-domain-file "master-account-domain.lisp")
  • When that is done, run docker-compose up -d If you set this up locally then by default your app will be made available on http://localhost:80

Frontend - EmberJS

If you use semantic.works then it does not really matter which frontend framework you use but for this Getting Started we will be using EmberJS as a template has already been build and is ready to be used.

  • Clone the following EmberJS frontend https://github.com/aatauil/ember-mu-auth-boilerplate
  • Navigate to the newly cloned repository and run npm i
  • After that is finished, run ember serve --proxy http://localhost:80
  • After your ember app has been succesfully served, you should be able to access the frontend in your browser at http://localhost:4200 More information about the frontend can be found in the README of the frontend template.

Note
The url entered after --proxy in the serve step needs to point to your backend in case you did not use the premade backend mentioned above.


Environment variables

ENV Description default required
SESSIONS_GRAPH Graph where session related information will be stored in. http://mu.semte.ch/application
ACCOUNTS_GRAPH Graph where account related information will be stored in. http://mu.semte.ch/application
HASH_STRENGTH The salt to be used to hash the password. Learn more 12

Development

This image uses the mu-javascript-template as base image (see Dockerfile). Therefor all functions and environment variables that the mu-javascript-template provides are also available in this image. Its highly advisable to read through the readme of the mu-javascript-template as it will show you how to setup a development environment where you can take advatage of logging, debugging, live reload and many functions.

Quick example on how your docker-compose.yml file for this service will look like in development mode:

    authentication:
      image: aatauil/mu-node-authentication-service
      ports:
        - 8888:80
        - 9229:9229
      environment:
        NODE_ENV: "development"
      links:
        - virtuoso:db
      volumes:
        - /path/to/local/cloned/mu-node-authentication-service/folder/:/app/
      labels:
        - "logging=true"
      restart: always
      logging: *default-logging

Note
When using mu-authorization, you probably will want your requests to go through there first instead of straight to 'virtuoso'. In the yaml file above we see that 'db' is linked directly to 'virtuoso'. Change this to the name of the authorization service (e.g. database) if you need it to go through mu-authorization first.

      links:
        - database:db

🧡 Contributing

Everyone can open an issue or send in a pull request.

📝 License

This project is MIT licensed.