Skip to content

Vuejs implementation of authorization web app

License

Notifications You must be signed in to change notification settings

pryv/app-web-auth3

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Authorization web app (app-web-auth v3)

Pryv.io web pages for app authorization, user registration and password reset.

You can take a look at the demo here.

This is a Template App developed with Vue.js to be adapted for each Pryv.io platform. It also serves as a reference if you prefer to use another framework.

These web pages are the "popup frame" that opens during the app authorization process, as well as registration and password reset.

Registration Change-Password Consent Reset-Password
1-signin 5-change-password 1-signin 1-signin

Table of contents

Fork repository for GitHub pages

After you have forked the repository on GitHub, you must adapt the upload script so it pushes to the gh-pages branch of your repository by modifying the following line as following:

  git clone [email protected]:{YOUR-GITHUB-ACCOUNT}/app-web-auth3.git dist && cd dist && git checkout gh-pages

In order for GitHub to build the GH pages once, you must make a commit in the gh-pages branch. An easy way to achieve this is to do a commit that adds an extra space or line at the end of a file.

Web pages flow

In this section, we explain how the 3 main functions of app-web-auth3 are implemented; namely authorizing client applications, registering new Pryv.io users and resetting forgotten passwords. We first present the logic flow and then provide additional details about the operations they perform.

Authorization flow

  1. (This step is happening outside app-web-auth3) The client application performs an auth request call, as explained here: API doc - Authorizing your app. As a response, the app receives an URL to open (e.g as a popup), which actually targets the app-web-auth3 auth page. This URL carries as query parameters the requesting permissions and requesting app id from the auth request, see API doc - Auth request

This step can be tested with:

  1. The app-web-auth3 auth page prompts the user to enter his Pryv.io username and password.

  2. Clicking on Sign-in triggers a login (login operation) returning a personal token for this user.

  3. Using the personal token, the app verifies the format of the requested permissions against the requesting app id to see if such a request was already accepted, if the permissions are different to one already provided for such an app id or if it is a new one (see checkAccess operation).

  4. The requested permissions are shown to the user, who can decide to Accept (acceptAccess operation) or Refuse (refuseAccess operation) granting access to the app by clicking on the corresponding button. If accepted, it creates a new app access.

  5. The authorization flow ends by returning (closeOrRedirect operation) the result of this flow: the new app access token or a message in case of error/refuse/cancelation to the requesting app.

Register user flow

It follows the account creation flows: API doc - account creation

  1. Upon loading, a list of available Pryv.io hostings is loaded (See API doc - Get hostings).

  2. A form asks for information about the new user: email, username, password, choice of hosting.

  3. Clicking on Create triggers the user creation.

  4. The registration flow ends and the new user is redirected to the demo dashboard.

Reset password request flow

  1. A form asks for a Pryv.io username or email.

  2. Clicking on Request password reset triggers the sending of a reset password email to the user (sent from the Pryv.io server/core) (See API doc - Reset password request).

  3. The user opens the email and clicks on the reset link. The link targets the password reset page, but this time provides a reset token as query string.

  4. A new form is presented to the user asking for his username or email and a new password.

  5. Clicking on Change password will update the password with the new one, using the reset token (See API doc - Reset password).

Operations in details

login

Resolves the username if an email is provided, verifies the username existence then uses the provided Pryv.io credentials (username, password) to login with the Pryv.io API (See API doc login).

checkAccess

Checks the requested app access (especially the permissions it contains) and compares it with eventually existing ones (only accesses of type 'app' are considered here).

Reference: API doc CheckApp Access

The API response will contain the following fields:

  • in any case, checkedPermissions will contain the set of requested permissions that has been checked and corrected (for example to ensure that stream names stay unique using provided defaultNames).
  • if a similar app access already exists and its permissions match the requested permissions, matchingAccess will contain the existing ,matching access.
  • if a similar app access already exists but its permissions do not match the requested permissions, mismatchingAccess will contain the mismatching access.

Knowing that, this operation continues as follow:

If a matchingAccess exists, the Pryv.io register is notified by sending an AcceptedAccessState (which contains the username and the app access token) to the poll endpoint so that the app access token can further be retrieved by the app doing the polling (See auth flow, step 5).

Otherwise, we first replace the permissions list with the checkedPermissions and then show them to the user so that he can consent (or not) to the creation of the new app access (auth flow, step 4).

If a mismatchingAccess exists, we still show the checkedPermissions to the user, but instead of creating a new access upon user consent (auth flow, step 4), we just update the existing one with the new permissions. Updating an access is a two step process delete then create to preserve history.

acceptAccess

Triggered when the user accepts to consent to the new app access.

  1. (optional) Delete if it's an update, first delete the existing one. API doc Access delete
  2. Create the access according to provided username, personalToken and permissionsList (or updates an existing mismatchingAccess using its access id). API doc Access create
  3. Notify requestee by sending an AcceptedAccessState (which contains the pryvApiEndpoint) to the poll endpoint (so that the app token can further be retrieved by the app doing polling) and the auth flow ends (closeOrRedirect operation).

POST {poll url}

API doc - Auth request - result accepted

{
	"status": "ACCEPTED",
	"pryvApiEndpoint": "https://{token}@{apiEndpoint}",
	"username": "..will be deprecated..",
	"token": "..will be deprecated..",
}

refuseAccess

Triggered when the user refuses to consent to the new app access, it notifies the Pryv.io register by sending a RefusedAccessState (which contains nothing more than a refusal message) and ends the auth flow (closeOrRedirect operation).

POST {poll url}

API doc - Auth request - result refused

{
	"status": "REFUSED",
	"reasonID": "...",
	"message": "...."
}

closeOrRedirect

If the requesting app specified a returnUrl within the auth request, the current url is redirected to the returnUrl and the result of the auth flow (app token within AcceptedAccessState or message within RefusedAccessState) will be present as query parameters.

Otherwise, the auth page is just closed and the requesting app will be able to retrieve the result of the auth flow by calling the polling endpoint on register (since it has been notified about AcceptedAccessState/RefusedAccessState).

Development and Deployment

Prerequisites

Node v12, yarn v1

Commands

Task Command
Setup dev environment yarn setup
Install dependencies yarn install
Create distribution in dist/ yarn build
Run the app locally in dev mode yarn start
Serve dist/ content with rec-la SSL cert yarn webserver
To manually test the auth flow yarn webserver-test
Run unit tests (-u to updates snapshots) yarn unit
Run E2E tests yarn e2e
Run E2E tests with snapshots yarn e2eS
Run eslint yarn lint
Publish to gh-pages yarn upload ${commit-message}

Tests

rec-la for local manual test

rec-la Provides a Webserver and SSL certificate pointing to localhost for testing purposes.

Run:

  • yarn build
  • yarn webserver

Open one of the entrypoint you need to test such as:

Note: you can override default hardcoded serviceInfoUrl with the query parameter pryvServiceInfoUrl as shown.

Testing Auth flow, with Rec-la

Once you have started yarn webserver also start yarn webserver-test and open https://l.rec.la:5443/. You might want to edit the page ./tests/webpage-auth/index.html.

Vue.js testing

Publish to github pages

If it is the first time you publish app-web-auth3, be sure to run yarn setup once.

Create a distribution with your changes by running yarn build.

Then, publish your changes by running yarn upload ${commit-message}

If you encounter conflicts while publishing, run yarn clear to reset the dist/ folder, then build and publish again.

Publish in Open Pryv.io environment

During the installation of Open Pryv.io, the app-web-auth3 files have been published in the ../public_html/access/ folder of your open-pryv.io repo. If you customize the application, you should copy the content from the app-web-auth3/dist/ folder to open-pryv.io/public_html and reboot Open Pryv.io .

Possible deployments and structure

This application is based on the Vue history router design. It exposes one single index.html file but the application has several entry points:

In order to expose these entrypoints, you can either :

Use Symbolic Links

Reference the entry points to dist/index.html.

The build process automatically creates the necessary links in dist/ and this folder can be directly exposed by a web sever.

The pages are accessible by https://your-app-domain.com/access/register.html

Use a reverse proxy, example with NGINX

Redirect requests to these endpoint to index.html with a reverse proxy. You can find an example for NGINX below.

We present here an example of NGINX configuration for using app-web-auth3 within a Pryv.io installation.

# Static Web: /static/nginx/conf/site.conf
server {
  listen               443;
  server_name          sw.pryv.me;
  access_log           /app/log/sw.access.log;
  ssl                  on;
  client_max_body_size 5M;

  # This allows to support old endpoints of app-web-auth2 (access.html, register.html, reset.html)
  # making them still reach app-web-auth3 index while not redirecting calls for static assets.
  if ($request_uri !~* "^/access/static/.*$") {
    rewrite ^.*$ /access/index.html;
  }

  location /access/ {
      proxy_pass        https://api.pryv.com/app-web-auth3/;
      proxy_set_header  Host 'api.pryv.com';
  }
}

Assets & Visual Usage and Customization

To customize assets and visual, you can refer to: https://github.com/pryv/assets-pryv.me.

License

Revised BSD license