Skip to content
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

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

Open
lamnot opened this issue Apr 12, 2018 · 1 comment
Open

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

lamnot opened this issue Apr 12, 2018 · 1 comment

Comments

@lamnot
Copy link

lamnot commented Apr 12, 2018

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"});
}
});`

@dashersw
Copy link
Owner

Hello @cohabo! Did you make any progress on this? It's hard for me to understand how you are making use of cote in this scenario. For example, the Sockend component doesn't have a connect method.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants