-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #499 from ITPNYU/main
Staging Release 11.13
- Loading branch information
Showing
18 changed files
with
661 additions
and
143 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
# To get started with Dependabot version updates, you'll need to specify which | ||
# package ecosystems to update and where the package manifests are located. | ||
# Please see the documentation for all configuration options: | ||
# https://docs.github.com/code-security/dependabot/dependabot-version-updates/configuration-options-for-the-dependabot.yml-file | ||
|
||
version: 2 | ||
updates: | ||
- package-ecosystem: "" # See documentation for possible values | ||
directory: "/" # Location of package manifests | ||
schedule: | ||
interval: "weekly" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
# Security Policy | ||
|
||
## Supported Versions | ||
|
||
Use this section to tell people about which versions of your project are | ||
currently being supported with security updates. | ||
|
||
| Version | Supported | | ||
| ------- | ------------------ | | ||
| 5.1.x | :white_check_mark: | | ||
| 5.0.x | :x: | | ||
| 4.0.x | :white_check_mark: | | ||
| < 4.0 | :x: | | ||
|
||
## Reporting a Vulnerability | ||
|
||
Use this section to tell people how to report a vulnerability. | ||
|
||
Tell them where to go, how often they can expect to get an update on a | ||
reported vulnerability, what to expect if the vulnerability is accepted or | ||
declined, etc. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,66 @@ | ||
import { TokenResponse } from "@/components/src/types"; | ||
import { NYUTokenManager } from "@/lib/server/nyuTokenCache"; | ||
import { Buffer } from "buffer"; | ||
import { NextResponse } from "next/server"; | ||
|
||
const NYU_AUTH_URL = "https://auth.nyu.edu/oauth2/token"; | ||
|
||
function getBasicAuthHeader(): string { | ||
const clientId = process.env.NYU_API_CLIENT_ID; | ||
const clientSecret = process.env.NYU_API_CLIENT_SECRET; | ||
|
||
if (!clientId || !clientSecret) { | ||
throw new Error("NYU credentials not configured"); | ||
} | ||
|
||
const credentials = `${clientId}:${clientSecret}`; | ||
return `Basic ${Buffer.from(credentials).toString("base64")}`; | ||
} | ||
|
||
export async function GET() { | ||
try { | ||
const tokenManager = NYUTokenManager.getInstance(); | ||
let tokenCache = await tokenManager.getToken(); | ||
if (!tokenCache) { | ||
const username = process.env.NYU_API_USER_NAME; | ||
const password = process.env.NYU_API_PASSWORD; | ||
|
||
const params = new URLSearchParams({ | ||
grant_type: "password", | ||
username, | ||
password, | ||
scope: "openid", | ||
}); | ||
|
||
const response = await fetch(NYU_AUTH_URL, { | ||
method: "POST", | ||
headers: { | ||
Authorization: getBasicAuthHeader(), | ||
"Content-Type": "application/x-www-form-urlencoded", | ||
}, | ||
body: params.toString(), | ||
// @ts-ignore | ||
rejectUnauthorized: false, | ||
}); | ||
|
||
const tokenResponse: TokenResponse = await response.json(); | ||
|
||
tokenManager.setToken( | ||
tokenResponse.access_token, | ||
tokenResponse.expires_in, | ||
tokenResponse.token_type, | ||
); | ||
tokenCache = await tokenManager.getToken()!; | ||
} | ||
return NextResponse.json({ | ||
isAuthenticated: true, | ||
expiresAt: new Date(tokenCache.expires_at).toISOString(), | ||
}); | ||
} catch (error) { | ||
console.error("NYU Auth error:", error); | ||
return NextResponse.json( | ||
{ error: "Internal server error" }, | ||
{ status: 500 }, | ||
); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,70 @@ | ||
import { ensureNYUToken } from "@/lib/server/nyuApiAuth"; | ||
import { NYUTokenManager } from "@/lib/server/nyuTokenCache"; | ||
import { NextRequest, NextResponse } from "next/server"; | ||
|
||
const NYU_API_BASE = "https://api.nyu.edu/identity-v2-sys"; | ||
|
||
export async function GET( | ||
request: NextRequest, | ||
{ params }: { params: { uniqueId: string } }, | ||
) { | ||
try { | ||
const authResult = await ensureNYUToken(); | ||
if (!authResult.isAuthenticated || !authResult.token) { | ||
return NextResponse.json( | ||
{ error: authResult.error || "Authentication required" }, | ||
{ status: 401 }, | ||
); | ||
} | ||
|
||
const apiAccessId = process.env.NYU_API_ACCESS_ID; | ||
|
||
if (!apiAccessId) { | ||
return NextResponse.json( | ||
{ error: "API access ID not configured" }, | ||
{ status: 500 }, | ||
); | ||
} | ||
|
||
const url = new URL( | ||
`${NYU_API_BASE}/identity/unique-id/primary-affil/${params.uniqueId}`, | ||
); | ||
url.searchParams.append("api_access_id", apiAccessId); | ||
|
||
const response = await fetch(url.toString(), { | ||
headers: { | ||
Authorization: `Bearer ${authResult.token}`, | ||
Accept: "application/json", | ||
}, | ||
}); | ||
console.log("response", response); | ||
|
||
if (!response.ok) { | ||
const errorText = await response.text(); | ||
console.error("NYU Identity API Error:", { | ||
status: response.status, | ||
body: errorText, | ||
uniqueId: params.uniqueId, | ||
}); | ||
|
||
if (response.status === 401) { | ||
NYUTokenManager.getInstance().clearToken(); | ||
} | ||
|
||
return NextResponse.json( | ||
{ error: `NYU API call failed: ${response.status}` }, | ||
{ status: response.status }, | ||
); | ||
} | ||
|
||
const userData = await response.json(); | ||
|
||
return NextResponse.json(userData); | ||
} catch (error) { | ||
console.error("Identity API error:", error); | ||
return NextResponse.json( | ||
{ error: "Failed to fetch identity data" }, | ||
{ status: 500 }, | ||
); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.