Skip to content

Commit

Permalink
prompt=none simulates mode based on user type
Browse files Browse the repository at this point in the history
  • Loading branch information
jmandel committed Dec 9, 2024
1 parent 2cd2bfb commit 50e6a7a
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 5 deletions.
2 changes: 1 addition & 1 deletion backend/lib/TokenCache.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ export interface TokenContext {
patient?: string
user: string
client_id: string
context: Record<string, any>
contex: Record<string, any>
exp: number
}

Expand Down
23 changes: 19 additions & 4 deletions backend/routes/auth/authorize.ts
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,7 @@ export default class AuthorizeHandler {
const params: AuthorizeParams = req.method === "POST" ? req.body : req.query

try {
console.log("handling authz", params.launch, req.params.sim);
var launchOptions = new LaunchOptions(String(params.launch || "") || req.params.sim || "")
} catch (ex) {
throw new InvalidRequestError("Invalid launch options: " + ex)
Expand Down Expand Up @@ -334,6 +335,7 @@ export default class AuthorizeHandler {
const { params, launchOptions } = this

const scope = new ScopeSet(decodeURIComponent(this.params.scope));
console.log("Create authz code with", scope);

const code: SMART.AuthorizationToken = {
context: {
Expand Down Expand Up @@ -407,6 +409,8 @@ export default class AuthorizeHandler {
}
}

console.log("Authz code as", code, launchOptions);

return jwt.sign(code, config.jwtSecret, { expiresIn: "5m" });
}

Expand Down Expand Up @@ -527,15 +531,26 @@ export default class AuthorizeHandler {
// Get the previous authorization context
const context = this.validateIdTokenHint(params.id_token_hint!);
console.log("Prev token context", context)



// Set up launch params from previous context
launchOptions.launch_type = "patient-standalone";
launchOptions.skip_login = true;
launchOptions.skip_auth = true;
launchOptions.patient.set(context.patient || "");

if (context.patient) {
launchOptions.patient.set(context.patient);
}
if (context.user.startsWith("Practitioner")) {
launchOptions.provider.set(context.user.split("/")[1]);
launchOptions.launch_type = "provider-standalone";
}
if (context.user.startsWith("Patient")) {
launchOptions.patient.set(context.patient);
launchOptions.launch_type = "patient-standalone";
}

launchOptions.scope = context.scope;

// Validate the request before proceeding
this.validateAuthorizeRequest();
console.log("validated authz request", launchOptions);
Expand Down

0 comments on commit 50e6a7a

Please sign in to comment.