admin管理员组

文章数量:1426918

I have a node.js backend for an ios app that will provide json data to the app. I want to handle client authentication for each app. The users do not need to create an account. I only want to identify the client apps when providing data and save some data for each client on the node server.

  1. How do I handle identifying each app on the server?
  2. If I need to create an API key, how do I handle that?
  3. If there is a way to authenticate the app when the app first accesses the API, how can I create a unique identifier for the app?
  4. Last, what do I need to know before I deploy the node server? Can I get away by just pointing a domain to my router, opening a port and serving the api from there or is it a must to have a web server setup to handle that?

Thank you

I have a node.js backend for an ios app that will provide json data to the app. I want to handle client authentication for each app. The users do not need to create an account. I only want to identify the client apps when providing data and save some data for each client on the node server.

  1. How do I handle identifying each app on the server?
  2. If I need to create an API key, how do I handle that?
  3. If there is a way to authenticate the app when the app first accesses the API, how can I create a unique identifier for the app?
  4. Last, what do I need to know before I deploy the node server? Can I get away by just pointing a domain to my router, opening a port and serving the api from there or is it a must to have a web server setup to handle that?

Thank you

Share Improve this question asked Apr 29, 2017 at 0:12 tewtew 2814 silver badges14 bronze badges 1
  • Have you done any research on your own? What have you tried? What has or hasn't worked? – Hydrothermal Commented Apr 29, 2017 at 2:39
Add a ment  | 

1 Answer 1

Reset to default 3

You can basically find a lot of blogs posts to get best practices to follow when designing an api. But here is an over all idea

  1. You can create a client key and send it on every api request or add as part of url

    Example: api.example./v1/users?client=android&version=1.1

  2. Use Middileware. You can either name as to your convenience or have a database to store key value to manage your clients. Example:

    Create a Middleware which does the handling of authentication and API key checker before you forward it to the routes.

    android => 0, ios => 1, web => 2

    url: api.example./v1/users?client=0&version=1.1

  3. There are many ways to create api keys. Here are some of them

    UUID - https://www.npmjs./package/uuid

    Json web token - https://github./auth0/node-jsonwebtoken

    Oauth - https://github./ciaranj/node-oauth

  4. Again, You have a lot of online posts explaining best practices to follow in production. If express.js, You can find best practices to follow here Express Production

This is just an overview. I request you to do a lot of research online and ask a relative more concrete problems you face towards your learning.

本文标签: javascriptNodejs client api keyStack Overflow