Skip to content

Commit 2790805

Browse files
committed
docs: Add documentation for the browser auth feature
1 parent b0b7bfb commit 2790805

6 files changed

Lines changed: 60 additions & 0 deletions

File tree

auth/src/main/java/org/openedx/auth/data/api/AuthApi.kt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,7 @@ interface AuthApi {
3838
@Field("grant_type") grantType: String,
3939
@Field("client_id") clientId: String,
4040
@Field("code") code: String,
41+
@Field("redirect_uri") redirectUri: String
4142
): AuthResponse
4243

4344
@FormUrlEncoded

auth/src/main/java/org/openedx/auth/data/repository/AuthRepository.kt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,7 @@ class AuthRepository(
4949
grantType = ApiConstants.GRANT_TYPE_CODE,
5050
clientId = config.getOAuthClientId(),
5151
code = code,
52+
redirectUri = "${config.getApplicationID()}://oauth2Callback"
5253
).mapToDomain().processAuthResponse()
5354
}
5455

core/src/main/java/org/openedx/core/config/Config.kt

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,10 @@ class Config(context: Context) {
2727
return getString(API_HOST_URL, "")
2828
}
2929

30+
fun getApplicationID(): String {
31+
return getString(APPLICATION_ID, "")
32+
}
33+
3034
fun getOAuthClientId(): String {
3135
return getString(OAUTH_CLIENT_ID, "")
3236
}
@@ -139,6 +143,7 @@ class Config(context: Context) {
139143

140144
companion object {
141145
private const val API_HOST_URL = "API_HOST_URL"
146+
private const val APPLICATION_ID = "APPLICATION_ID"
142147
private const val OAUTH_CLIENT_ID = "OAUTH_CLIENT_ID"
143148
private const val TOKEN_TYPE = "TOKEN_TYPE"
144149
private const val FAQ_URL = "FAQ_URL"
File renamed without changes.
Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
How to user Browser-based Login and Registration
2+
================================================
3+
4+
Introduction
5+
------------
6+
7+
If your Open edX instance is set up with a custom authentication system that requires logging in
8+
via the browser, you can use the ``BROWSER_LOGIN`` and ``BROWSER_REGISTRATION`` flags to redirect
9+
login and registration to the browser.
10+
11+
The ``BROWSER_LOGIN`` flag is used to redirect login to the browser. In this case clicking on the
12+
login button will open the authorization flow in an Android custom browser tab and redirect back to
13+
the application.
14+
15+
The ``BROWSER_REGISTRATION`` flag is used to redirect registration to the browser. In this case
16+
clicking on the registration button will open the registration page in a regular browser tab. Once
17+
registered, the user will **not** be automatically redirected to the application.
18+
19+
Usage
20+
-----
21+
22+
In order to use the ``BROWSER_LOGIN`` feature, you need to set up an OAuth2 provider via
23+
``<LMS>/admin/oauth2_provider/application/`` that has a redirect URL with the following format
24+
25+
``<application id>://oauth2Callback``
26+
27+
Here application ID is the ID for the Android application and defaults to ``"org.openedx.app"``. This
28+
URI scheme is handled by the application and will be used by the app to get the OAuth2 token for
29+
using the APIs.
30+
31+
Note that normally the Django OAuth Toolkit doesn't allow custom schemes like the above as redirect
32+
URIs, so you will need to explicitly allow the by adding this URI scheme to
33+
``ALLOWED_REDIRECT_URI_SCHEMES`` in the Django OAuth Toolkit settings in ``OAUTH2_PROVIDER``. You
34+
can add the following line to your django settings python file:
35+
36+
.. code-block:: python
37+
38+
OAUTH2_PROVIDER["ALLOWED_REDIRECT_URI_SCHEMES"] = ["https", "org.openedx.app"]
39+
40+
Replace ``"org.openedx.app"`` with the correct id for your application. You must list all allowed
41+
schemes here, including ``"https"`` and ``"http"``.
42+
43+
The authentication will then redirect to the browser in a custom tab that redirects back to the app.
44+
45+
NOTE: If a user logs out from the application, they might still be logged in, in the browser.

docs/how-tos/index.rst

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
"How-To" Guides
2+
###############
3+
4+
5+
.. toctree::
6+
:glob:
7+
8+
*

0 commit comments

Comments
 (0)