Skip to content

Banging Head, TypeError: ios.connect is not a function #6

@lamnot

Description

@lamnot

Hi Armagan,

I love the succitness and elegance of cote, its always worked for until now, I have this minor problem and have tried everything with no good result yet, what am i doing wrong in calling like this, "res.redirect(bitrix24.auth.authorization_uri);" is it forbidden to call the internal app.get from cote, how can i go around this?

`const app = require('express')(),
server = require('http').Server(app),
io = require('socket.io')(server),
cote = require('cote');
const b24 = require('b24');

// A Responder that shall listen for the Rest Api calls
const responder = new cote.Responder({ name: ' bitrix rest calls API responder ' });

const ios = new cote.Sockend(io, { name: 'end-user sockend server' });

// // A Publisher that shall notify for the Rest API calls
// const publisher = new cote.Publisher({ name: 'arbitration publisher' });

// const subscriber = new cote.Subscriber({ name: 'arbitration subscriber' });

// B24 setup
const bitrix24 = new b24.Bitrix24({
config: {
mode: "api",
host: "wwwwww",
client_id : "xxxxxxxxxxxxx",
client_secret : "xxxxxxxxxxxx",
redirect_uri : "xxxxxxxxxxxxxxxxxx"
},
methods: {
async saveToken(data){
//Save token to database
},
async retriveToken(){
//Retrive token from database
return {
access_token: "youraccesstoken",
refresh_token: "yourrefreshtoken"
}
}
}
})

app.get('/auth', function (req, res) {
console.log(${req.ip} requested end-user interface);

res.redirect(bitrix24.auth.authorization_uri);

res.sendFile(__dirname + '/index.html');

});

server.listen(3000);

// Bitrix auth
responder.on('api', (req, res) => {
ios.connect('/auth');
});

// Callback service parsing the authorization token and asking for the access token
app.get('/callback', async (req, res) => {
try{
const code = req.query.code;
console.log(code);
const result = await bitrix24.auth.getToken(code);
console.log(result);
return res.json(result);
}catch(err){
console.log(err)
return res.status(500).json({message:"Authentication Failed"});
}
});`

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions