I'm a regular reader here at stack overflow but this is my first question.
I'm developing an authorization-server using the OAuth2 specs. And I just got stuck with how do I ensure the first-party client authenticity while using the password flow. I read many forums and this is what I got:
Javascript single-page clients
This blog post by Alex Bilbie, he states that to avoid the client_secret problem we should just:
It’s simple; proxy all of your API calls via a thin server side component. This component (let’s just call it a proxy from here on) will authenticate ajax requests from the user’s session. The access and refresh tokens can be stored in an encrypted form in a cookie which only the proxy can decrypt. The application client credentials will also be hardcoded into the proxy so they’re not publicly accessible either.
But now this proxy can be accessed by someone impersonating my angular app. And then I came across this blog post from Andy Fielder: How Secure is the OAuth2 Resourc Owner Password Flow for Single Page Apps. He basically says to rely on CORS to avoid impersonating JS clients.
It is a good idea to use both approaches to secure my JS app?
Native Apps (Desktop and Mobile)
In the case of mobile apps, I only found cases for Authorization Code and Implicit flows. This is not what I want, as the redirects will compromise the user experience. So my thoughts on this is:
I will use the ROP flow and then register the client with a
client_id
generated for this particular installation and attach it to the user account, receiving theaccess_token
and aclient_secret
as response. Any other token request made by this client MUST carry this credentials (as theclient_id
is specific for the installation, I will be able to check if this client is already authenticated). This way if someone uses any credential for impersonating a client, or even registers a bogus client, I can take mesures to revoke the user and client access.
I know that this can be overthinking, and I also know that some of this matters doesn't avoid anything. I just feel that is my job to protect my API as much as I can.
I would really appreciate your thoughts about this matters! Am I really overthinking? Should I just use the concept of a 'public client' and carry on?
Thank you all and happy coding!