Currently we have a SPA and API and SPA sends email/password to API and API returns response with two secure / HttpOnly / Lax cookies. First cookie is access token with short TTL (custom JWT is stored inside cookie) and second one is a refresh token with long TTL. SPA makes requests to API with those cookies, and API verifies if access token is expired and refreshes it when needed by reading refresh token from cookie and setting new access token cookie.
Because we will have more API clients soon (mobile app and machine-to-machine clients) we wanted to make use of OAUTH to standarize authorization. After making some research it seems that OAUTH is good for everything except SPAs because storing refresh tokens in browser is not secure and should be avoided. For mobile it seems to be secure-enough because refresh token can be stored in OS keychain or something like that.
So it would be reasonable to still use secure cookies for SPA and access tokens for mobile and machine-to-machine. To make it consistent we would like to just have regular oauth access / refresh tokens stored inside cookies and on API side treated in a same way that bearer tokens passed in authorization header. Our SPA and API are in same domain (different subdomains) and this is more about one API and many clients case.
We are considering following options for SPA:
Just use Resource Owner Password Flow - while it's not recommended, it can be used from highly trusted "client" - in our case that would be SPA sending credentials to API and API calling oauth server (with client id, secret and user credentials) to get access token and refresh token and then return those tokens in secure cookies back to SPA.
I am not sure if this is possible but I was thinking of splitting Authorization Code Flow between SPA and API. SPA redirects to oauth authorization page, user logins on hosted login page and is redirected back to SPA with authorization code. Then SPA instead of calling /oauth/token on oauth server it sends authorization code to API and API makes final call to /oauth/token on oauth server to get access token and refresh token and store it in cookies. Does it reduce security in any way?
Are there any other options?`