Web Developers: Add our simple module before June 14 and earn up to 125,000 NOS!

If you’re familiar with any server language (PHP, NodeJS, C#, or anything else), implementing nOS ID with your app is easy.

Dean van Dugteren
nOS - Decentralized Curation Platform
6 min readMay 22, 2019

--

Integrate nOS ID into your app before June 14th 2019 and win up to 125,000 NOS!

We’re talking about the nOS ID Developer Competition. View the competition rules and details here.

Summary

nOS ID is a simple to use identity system that can be integrated with apps to gain the following features:

  • Let users log in to your app with a single click (similar to “Login with Facebook”), using their nOS.app account.
  • Retrieve user data and their verified cryptocurrency addresses.

Benefits

  • Build secure server-side applications that integrate with your own crypto-currency token (or smart contract).
  • Use your favorite language & framework.
  • One-click registration and login for server-side nOS applications.
  • Offer benefits (app features, game xp, points) to users based on their token balance without a hosted wallet (hosted wallets are insecure and add loads of liability to the app).
  • Increased security and conversion rates for crypto payments and transactions.
  • Integrate with nOS Client to let users make one-click payments (and any other type of transaction) directly in your application, without ever needing their private keys or a deposit address.

Available User Data

This is the data you can read from authorized users:

  • Email
  • Username
  • Verified user crypto-currency addresses
  • NOS Holding Score

More features for reading (and writing) user data will be available in the future.

Authentication Flow

The authentication flow follows the OAuth 2 standard with the code response type.

  1. Register an App.
  2. Generate an Authorization URL for the user.
  3. On authorization, send the returned code variable to nOS.app OAuth 2 API together with your Client ID and Secret.
  4. Retrieve Access Token.
  5. Send HTTP requests to nOS.app API using Access Token to read/write user data of the user that the Access Code belongs to.

Learn more about OAuth 2: https://www.oauth.com/oauth2-servers/accessing-data/

Tutorial

1. Register your App

First you’ll need to register your nOS ID App at nos.app/oauth/index.

  1. Website URL is the Home Page of your application.
  2. Redirect URI is the URI that nOS.app redirects the user to after approving your application. The Redirect URI will have a code and state variable, which you will use to retrieve an Access Token.

2. Retrieve App Details

You’ll need the Client ID, Client Secret, and Authorization URL.

  • The Client ID and Secret are used to authenticate the Application when it makes API requests to nOS.app.
  • The Authorization URL is where you send users to to Authorize your Application.

3. Generate a random state token

The Authorization URL supplied by nOS.app ends with ?state=example. Replace example with a randomly generated token that you store in the user's browser (e.g. with a cookie or session key).

When the user authorizes the application, nOS.app adds the state variable in the Redirect URI. You can use this to check if the same user has authorized the application in the same browser session.

PHP Example

This is a functional PHP example. Make sure to replace the common variables with your own app variables (Client ID, Secret).

Redirect the user to the $url with a button or redirect. The user will be redirected to nOS.app and see the following dialog:

4. Handle the Authorization

Upon clicking Approve, the user is redirected to your Redirect URI. The Redirect URI will have 2 variables: codeand state.

Flow

  1. Compare the state value with the state you stored in the user's browser session in Step 3 to verify the user session.
  2. If the state matches, make a POST request to nos.app to retrieve the user's Access Token.
  3. Store the Access Token to your database.

PHP Example

5. Using the Access Token to Read User Data

You can use the Access Token token to register the user to your app, log them in, connect user data to an existing account on your app, and build features around your users’ cryptocurrency accounts. For example you can check if a user holds a specific amount of your token on one of their verified cryptocurrency addresses (retrieved by nOS.app API), and unlock a feature in an app, or grant bonus points/give starting XP in a game, etc.

  • If you want to register the user, you should retrieve the user’s Account Details using the nOS.app API and store it in your database together with the Access Token.
  • If you want to log in the user, you can check if the Access Token belongs to an existing user in your database.

In this tutorial we’re saving the Access Token to the user’s browser session. This is not recommended in production. You should store the Access Token in your database, and use a separate session token to keep the user logged in.

PHP Example

Full PHP Example

For a full PHP example, view the nOS ID documentation here.

Good luck!

Need inspiration? The game nOS Poker uses nOS ID for its login system, and NOS for free poker tournaments.

--

--