Which authentication strategy should I use for my API?

后端 未结 1 1296
迷失自我
迷失自我 2020-12-16 06:54

I have a client-side angular-js application. And I have a server-side nodejs API. The client-side and the server-side application are located on different domains. The clien

1条回答
  •  -上瘾入骨i
    2020-12-16 07:37

    It is important to understand the difference between web applications and web services. A web application serves markup, JavaScript, CSS and image files and often uses cookie based authentication (but can use any other implicit authentication mechanism). Any request the browser makes is automatically authenticated.

    Web services on the other hand often use bearer token authentication. When a client in a browser, fat client or on a mobile device communicates with the API, it sends along a token in the Authorization header of the HTTP request. The header has to be explicitly attached to the request in the JavaScript or native code executing the HTTP request.

    In Single Page Applications (SPA), the web application is missing and the markup, JavaScript, CSS and images are served from the browser without authentication. Only the requests to the web services are authenticated, typically using a JWT token.

    In your case, if you want only authorized users to be able to download images, and other files, you should consider building a web application. Use a security protocol like or OpenID Connect to authenticate your users. Choose an authorization server that supports both OpenID Connect for your web application and OAuth2 for your web service.

    0 讨论(0)
提交回复
热议问题