Invalid token. Please reinitiate login.
See original GitHub issueDescribe the bug Getting “Invalid token. Please reinitiate login.” HTTP 401 error in Moodle.
Expected behavior Show “It’s alive”
Provider logs LTI Provider is listening on port 3000! LTI provider config:
App Url: / Initiate login URL: /login Keyset Url: /keys Session Timeout Url: /sessionTimeout Invalid Token Url: /invalidToken provider:main Platform already registered. +37ms provider:main Platform already registered. +10ms provider:main Platform already registered. +7ms provider:main Receiving request at path: /login +4s provider:main Receiving a login request from: http://www.mymoodle.local +0ms provider:main Redirecting to platform authentication endpoint +2ms provider:main Generated state: c2735a621668668e +0ms provider:main Login request: { response_type: ‘id_token’, response_mode: ‘form_post’, id_token_signed_response_alg: ‘RS256’, scope: ‘openid’, client_id: ‘GISQB0HdF95ijvc’, redirect_uri: ‘http://192.168.50.59:3000’, login_hint: ‘2’, nonce: ‘Pm3Dp6GRYlXC4nb9CDM2vA==’, prompt: ‘none’, state: ‘c2735a621668668e’, lti_message_hint: ‘2’, lti_deployment_id: ‘1’ } +8ms provider:main Receiving request at path: / +75ms provider:main Path does not match reserved endpoints +0ms provider:main Cookies received: +0ms provider:main [Object: null prototype] {} +0ms provider:main No LTIK found +0ms provider:main Request body: [Object: null prototype] { error: ‘invalid_request’, state: ‘c2735a621668668e’ } +1ms provider:main Receiving request at path: /invalidToken +23ms
Screenshots
require('dotenv').config()
const path = require('path')
// Require Provider
const LTI = require('ltijs').Provider
// Configure provider
const lti = new LTI('APPLTREEFRUIT',
{ url: `mongodb://${process.env.DB_HOST}:${process.env.DB_PORT}/${process.env.DB_NAME}` ,
connection: {
useUnifiedTopology: true ,
useNewUrlParser: true,
authSource: 'admin',
auth: {
user:process.env.DB_USER,
password: process.env.DB_PASSWORD
}
}
},
{ appUrl: '/',
loginUrl: '/login',
logger: true ,
})
let setup = async () => {
// Deploy and open connection to the database
await lti.deploy()
// Get the public key generated for that platform
let plat = await lti.registerPlatform({
url: 'http://www.mymoodle.local',
name: 'Moodle Local',
clientId: 'GISQB0HdF95ijvc',
authenticationEndpoint: 'http://172.16.238.38/mod/lti/auth.php',
accesstokenEndpoint: 'http://172.16.238.38/mod/lti/token.php',
authConfig: { method: 'JWK_SET', key: 'http://172.16.238.38/mod/lti/certs.php' }
})
// Set connection callback
lti.onConnect((connection, request, response) => {
// Call redirect function
console.log("OnConnect:")
lti.redirect(response, '/main')
}, { secure: false })
// Set main endpoint route
lti.app.get('/main', (req, res) => {
// Id token
console.log("LOCALS:")
console.log(res.locals)
console.log("")
res.send('It\'s alive!')
})
}
setup()
Ltijs version 4.1.0
NodeJS version v14.5.0
Platform used Moodle tool settings: Tool URL: http://192.168.50.59:3000 Login URL: http://192.168.50.59:3000/login Redirect URL: http://192.168.50.59:3000 Public key URL: http://192.168.50.59:3000/keys (also tried copy/paste keys instead of URL)
Moodle tool config shows Platform ID: http://www.mymoodle.local Client ID: GISQB0HdF95ijvc Deployment ID: 1 Public keyset URL: http://www.mymoodle.local/mod/lti/certs.php Access token URL: http://www.mymoodle.local/mod/lti/token.php Authentication request URL: http://www.mymoodle.local/mod/lti/auth.php
Additional context Running bitnami/moodle in docker mapped to port 80 on localhost Running LTIJS in vscode remote container mapped to port 3000 on localhost www.mymoodle.local is 172.16.238.38 localhost is 192.168.50.59
Issue Analytics
- State:
- Created 3 years ago
- Comments:6 (4 by maintainers)
I installed Moodle 3.7 on a clean virtual machine following the Ubuntu instructions and it is working now. I followed the steps in your Medium article. So it was definitely something to do with my docker setup or environment. I wonder if it had to do with DNS since I was running both Moodle and VSCode in docker containers. That’s why I was trying to use IP addresses initially. Thanks for your help.
I see, i’m glad it worked out!