Replies: 1 comment
-
Architecture
Note on permissions
OpenID/OAuth2
Which flow for our application (pyrog, pypa, etc.) ?The question is implicit flow or authz code flow ? Implicit
Authz code
Implementing the Authz code flowBrowser side (pyrog front, pypa front, etc.)
Clients (Pyrog back, river, pypa back, etc.)
Resource providers
OpenID/OAuth2 provider
About the end-users logging in only once (point 5.)
Which flow for direct access and CLI applications ?
References
|
Beta Was this translation helpful? Give feedback.
-
OIDC
Requirements
Specification
This flow enable the ability to keep all of the steps involved in obtaining
an access token outside of the Javascript application (the browser).
In this case, the Application Server initiates the OAuth flow itself,
by redirecting the browser to the authorization endpoint (B). When
the user is redirected back, the browser delivers the authorization
code to the application server (C), where it can then exchange it for
an access token at the token endpoint (D) using its client secret.
The application server then keeps the access token and refresh token
stored internally, and creates a separate session with the browser-
based app via a traditional browser cookie (E).
When the JavaScript application in the browser wants to make a
request to the Resource Server, it instead makes the request to the
Application Server (F), and the Application Server will make the
request with the access token to the Resource Server (H), and forward
the response (H) back to the browser.
The Application Server SHOULD be considered a confidential client,
and issued its own client secret. The Application Server SHOULD use
the OAuth 2.0 Authorization Code grant with PKCE to initiate a
request for an access token.
https://www.ory.sh/oauth2-for-mobile-app-spa-browser/
https://www.liip.ch/en/blog/authorization-code-with-pkce-on-django-using-django-oauth-toolkit
Security of the connection between code running in the browser and
this Application Server is assumed to utilize browser-level
protection mechanisms. Details are out of scope of this document,
but many recommendations can be found in the OWASP Cheat Sheet series
(https://cheatsheetseries.owasp.org/), such as setting an HTTP-only
and Secure cookie to authenticate the session between the browser and
Application Server.
In this scenario, the session between the browser and Application
Server SHOULD be a session cookie provided by the Application Server.
Django
In a Django backend, the Application Server would be the auth backend and a middleware through
which the requests are processed.
The Javascript application should have a link to a route of the backend api,
typically
/oidc/authenticate/
, which will redirect the user to the authorization endpoint.The user is then a redirected back to the redirect_uri
/oidc/callback
which will redirectthe user back to the Javascript application.
The refresh token is stored in the database and a
separate Django session is created. In Django Rest Framework, we would use
a Session Authentication.
https://www.django-rest-framework.org/api-guide/authentication/#sessionauthentication
The refresh token is used to check every now and then the user state by retrieving another access
token. If it fails, the session is destroyed. No need to store the access token.
A Session Authentication creates two cookies: a CSRF cookie and a session cookie.
The session cookie is a SameSite HTTP-Only cookie sent along every requests made by
the Javascript application to the Application Server. The CSRF cookie can be accessed by the
javascript code and its token should be added to every request headers.
Hapi FHIR
Keeping the same session across the stack
Scenario 1: API access through a browser
The API shares the same domain with the Django backend and has access to the session cookie.
The Django backend could communicate the session state and user infos to the API.
CSRF tokens should also be handled in some way...
Scenario 2: direct API access from another third party backend (no frontend)
Maybe an application password should be set for this...
References
https://tools.ietf.org/html/draft-ietf-oauth-browser-based-apps-07#page-6
https://oauth.net/articles/authentication/
Beta Was this translation helpful? Give feedback.
All reactions