Skip to content

integrate mitxonline api #2256

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 11 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
41 changes: 39 additions & 2 deletions config/apisix/apisix.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,10 @@ upstreams:
nodes:
"nginx:${{NGINX_PORT}}": 1
type: roundrobin
- id: 2
nodes:
"192.168.1.50:8013": 1
type: roundrobin

routes:
- id: 1
Expand All @@ -22,7 +26,9 @@ routes:
ssl_verify: false
session:
secret: ${{APISIX_SESSION_SECRET_KEY}}
cookie: { lifetime = 1209600 }
cookie:
lifetime: 1209600
domain: ${{CSRF_COOKIE_DOMAIN}}
logout_path: "/logout/oidc"
post_logout_redirect_uri: ${{APISIX_LOGOUT_URL}}
unauth_action: "pass"
Expand Down Expand Up @@ -53,7 +59,9 @@ routes:
ssl_verify: false
session:
secret: ${{APISIX_SESSION_SECRET_KEY}}
cookie: { lifetime = 1209600 }
cookie:
lifetime: 1209600
domain: ${{CSRF_COOKIE_DOMAIN}}
logout_path: "/logout/oidc"
post_logout_redirect_uri: ${{APISIX_LOGOUT_URL}}
unauth_action: "auth"
Expand All @@ -69,4 +77,33 @@ routes:
uris:
- "/admin/login/*"
- "/login"
- id: 3
name: "mitxonline-wildcard"
desc: "General route for the mitxonline application, includes user data if any."
priority: 10
upstream_id: 2
plugins:
openid-connect:
client_id: ${{KEYCLOAK_CLIENT_ID}}
client_secret: ${{KEYCLOAK_CLIENT_SECRET}}
discovery: ${{KEYCLOAK_DISCOVERY_URL}}
realm: ${{KEYCLOAK_REALM_NAME}}
scope: "openid profile ol-profile"
bearer_only: false
introspection_endpoint_auth_method: "client_secret_post"
ssl_verify: false
session:
secret: ${{APISIX_SESSION_SECRET_KEY}}
cookie:
lifetime: 1209600
domain: ${{CSRF_COOKIE_DOMAIN}}
logout_path: "/logout"
post_logout_redirect_uri: ${{APISIX_LOGOUT_URL}}
unauth_action: "pass"
proxy-rewrite:
regex_uri:
- "/mitxonline/(.*)"
- "/$1"
uris:
- "/mitxonline/*"
#END
1 change: 1 addition & 0 deletions docker-compose.services.yml
Original file line number Diff line number Diff line change
Expand Up @@ -119,6 +119,7 @@ services:
- apisix
image: apache/apisix:latest
environment:
- CSRF_COOKIE_DOMAIN=${CSRF_COOKIE_DOMAIN:-.odl.local}
- KEYCLOAK_REALM_NAME=${KEYCLOAK_REALM_NAME:-ol-local}
- KEYCLOAK_CLIENT_ID=${KEYCLOAK_CLIENT_ID:-apisix}
- KEYCLOAK_CLIENT_SECRET=${KEYCLOAK_CLIENT_SECRET}
Expand Down
1 change: 1 addition & 0 deletions frontends/api/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@
"ol-test-utilities": "0.0.0"
},
"dependencies": {
"@mitodl/mitxonline-api-axios": "^2025.5.23",
"@tanstack/react-query": "^5.66.0",
"axios": "^1.6.3"
}
Expand Down
28 changes: 25 additions & 3 deletions frontends/api/src/mitxonline/clients.ts
Original file line number Diff line number Diff line change
@@ -1,13 +1,35 @@
import { EnrollmentsApi, ProgramsApi, CoursesApi } from "./generated/v0/api"
import {
B2bApi,
CoursesApi,
EnrollmentsApi,
ProgramsApi,
UsersApi,
} from "@mitodl/mitxonline-api-axios/v1"
import axios from "axios"

const axiosInstance = axios.create({})
const axiosInstance = axios.create({
baseURL: process.env.NEXT_PUBLIC_MITXONLINE_API_BASE_URL,
xsrfCookieName: process.env.NEXT_PUBLIC_CSRF_COOKIE_NAME,
xsrfHeaderName: "X-CSRFToken",
withXSRFToken: true,
withCredentials:
process.env.NEXT_PUBLIC_MITOL_AXIOS_WITH_CREDENTIALS === "true",
})

const BASE_PATH =
process.env.NEXT_PUBLIC_MITXONLINE_API_BASE_URL?.replace(/\/+$/, "") ?? ""

const usersApi = new UsersApi(undefined, BASE_PATH, axiosInstance)
const b2bApi = new B2bApi(undefined, BASE_PATH, axiosInstance)
const enrollmentsApi = new EnrollmentsApi(undefined, BASE_PATH, axiosInstance)
const programsApi = new ProgramsApi(undefined, BASE_PATH, axiosInstance)
const coursesApi = new CoursesApi(undefined, BASE_PATH, axiosInstance)

export { enrollmentsApi, programsApi, coursesApi, axiosInstance }
export {
usersApi,
b2bApi,
enrollmentsApi,
programsApi,
coursesApi,
axiosInstance,
}

This file was deleted.

This file was deleted.

Loading
Loading