-
Notifications
You must be signed in to change notification settings - Fork 6.3k
Feature/openid connect #3093
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
Feature/openid connect #3093
Changes from 3 commits
d189ffc
5f59e99
e1abd86
906e7b6
12c813f
0440796
4fcfab2
a11d9a9
1532cb5
2a0c448
6add98b
3ac81d9
aabfded
c3c305c
153e89b
d5ffe24
9e2b4f3
af31604
793817b
d503138
f2f731a
becd7da
ed29b32
cf1ad0d
ab718f1
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,7 @@ | ||
import { field, logger } from "@coder/logger" | ||
import * as express from "express" | ||
import * as expressCore from "express-serve-static-core" | ||
import { RequestContext } from "express-openid-connect" | ||
import qs from "qs" | ||
import safeCompare from "safe-compare" | ||
import { HttpCode, HttpError } from "../common/http" | ||
|
@@ -16,6 +17,7 @@ declare global { | |
export interface Request { | ||
args: DefaultedArgs | ||
heart: Heart | ||
oidc: RequestContext | ||
} | ||
} | ||
} | ||
|
@@ -69,6 +71,29 @@ export const authenticated = (req: express.Request): boolean => { | |
? safeCompare(req.cookies.key, req.args["hashed-password"]) | ||
: req.args.password && safeCompare(req.cookies.key, hash(req.args.password))) | ||
) | ||
case AuthType.Openid: | ||
console.log(req.oidc.user) | ||
|
||
console.log(req.oidc.isAuthenticated()) | ||
|
||
const groupClaim = req.args["openid-group-claim"] | ||
const userGroup = req.args["openid-user-group"] | ||
|
||
if (req.oidc.isAuthenticated()){ | ||
for (const key in req.oidc.idTokenClaims) { | ||
var claims = <string[]>req.oidc.idTokenClaims[key] | ||
if (key == groupClaim) { | ||
for (const value in claims) { | ||
if(userGroup == claims[value]) { | ||
return true | ||
} | ||
} | ||
} | ||
} | ||
throw new HttpError("Unauthorized", HttpCode.Unauthorized) | ||
} | ||
|
||
return false | ||
|
||
default: | ||
throw new Error(`Unsupported auth type ${req.args.auth}`) | ||
} | ||
|