ltijs icon indicating copy to clipboard operation
ltijs copied to clipboard

URL with path redirected incorrectly

Open ChaseIngebritson opened this issue 4 years ago • 5 comments

Describe the bug If the server's URL includes a path, the LTI incorrectly redirects to a URL that does not include that path after session validation. For example if my server is hosted at https://api.example.com/prod/ and I access the LTI middleware at https://api.example.com/prod/lti/login and the session validation succeeds, the request is redirected to https://api.example.com/lti without the /prod path, which often times results in an unauthorized error.

Expected behavior The library should redirect requests in a way that accounts for being hosted at a path instead of just the base domain. For example if https://api.example.com/prod/login should be redirected to https://api.example.com/prod/?ltik= after successful session validation

Ltijs version

  • Version 5.7.7

NodeJS version

  • Version 12

Platform used

  • Canvas

Additional context It looks like the line causing this can be found at Provider.js Line 348. Also hopefully this isn't out of scope and I'm not missing a super obvious resolution.

ChaseIngebritson avatar Jun 17 '21 21:06 ChaseIngebritson

Same issue. Any workaround?

josepaiva94 avatar Nov 12 '21 20:11 josepaiva94

In my case, I'm passing my API Gateway URL through Route 53 and removing the /prod path used in my example above. So if you have the option, an alias record may help.

ChaseIngebritson avatar Nov 12 '21 20:11 ChaseIngebritson

No, I don't have that option unfortunately.

josepaiva94 avatar Nov 12 '21 20:11 josepaiva94

A possible workaround you could do is start the lti server in serverless mode and then mount it on your own express app. This way req.baseUrl should be relative to where lti.app is mounted

const lti = lti.setup(
    {/* database config */},
    {
        "appRoute" : "/",
        "loginRoute" : "/login",
        "keysetRoute" : "/keys",
    },
)

await lti.deploy({"serverless" : true})

const app = express()
app.use("/prod/lti", lti.app)

app.listen(3000)

Just be aware that any routes outside of /prod/lti wont get blocked by ltijs if the user isn't authenticated

georgehb avatar Nov 19 '21 16:11 georgehb

Still an issue - definitely a blocker for deploying when doing test/stage/prod. Any solutions?

rPayne-oes avatar Apr 18 '23 06:04 rPayne-oes