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

controller.req.data.post is undefined and websocket authorization #203

Closed
KiPSOFT-zz opened this issue Sep 28, 2014 · 24 comments
Closed

controller.req.data.post is undefined and websocket authorization #203

KiPSOFT-zz opened this issue Sep 28, 2014 · 24 comments

Comments

@KiPSOFT-zz
Copy link

Hi peter;

I'm using version 1.5 and use controller.req.data.post but last version getting this error;

default ---> TypeError: Cannot read property 'post' of undefined ([object Object]) TypeError: Cannot read property 'post' of undefined

second problem:

i'm using authorization module and websocket request. i'm getting error in websocket request.

ReferenceError: req is not defined ReferenceError: req is not defined at WebSocketClient.protocol (/var/www/vw_kodlar/client/generator_web/node_modules/total.js/index.js:5:31885) at WebSocketClient.prepare (/var/www/vw_kodlar/client/generator_web/node_modules/total.js/index.js:6:914) at EventEmitter.Framework._upgrade_continue (/var/www/vw_kodlar/client/generator_web/node_modules/total.js/index.js:3:951) at /var/www/vw_kodlar/client/generator_web/node_modules/total.js/index.js:3:809 at EventEmitter.Users._onAuthorization (/var/www/vw_kodlar/client/generator_web/modules/authorization.js:22:588) at EventEmitter.framework.onAuthorization (/var/www/vw_kodlar/client/generator_web/modules/authorization.js:22:3788) at EventEmitter.Framework._upgrade_prepare (/var/www/vw_kodlar/client/generator_web/node_modules/total.js/index.js:3:540) at EventEmitter.Framework._upgrade (/var/www/vw_kodlar/client/generator_web/node_modules/total.js/index.js:2:31827) at Server. (/var/www/vw_kodlar/client/generator_web/node_modules/total.js/index.js:2:21383) at Server.EventEmitter.emit (events.js:106:17)

Problems occurred when updating to the latest version, a little bit about backwards compatibility problems.

Thanks.

@petersirka
Copy link
Collaborator

Hi @KiPSOFT,
I removed this property, because I added a middleware (same is in express.js). So I had to add a more functionality like express.js. This was a big change and sorry for backward compatibility.

Thanks.

@petersirka
Copy link
Collaborator

But remained:

POST/PUT:
controller.post --> controller.req.body
controller.body --> controller.req.body
controller.req.body

GET/DELETE:
controller.get --> controller.req.query
controller.query --> controller.req.query
controller.req.query

@KiPSOFT-zz
Copy link
Author

Thanks for quick response peter. How to read this change list ? because controller.framework.config return undefined. i'm changed to controller.config worked.

What do you think about a websocket authorization problem ?

@petersirka
Copy link
Collaborator

Yes, I normalized names because older version framework has many unnecessary links. So controller.framework was removed because framework is a global variable. controller.config is a property that reads a value from framework.config.

I don't know about the problem of websocket authorization. Can you describe it?
Thanks.

@KiPSOFT-zz
Copy link
Author

My source structure;

definitions/authorization.js

framework.once('load', function() {

    var self = this;
    var auth = self.module('auth');

    auth.onAuthorization = function(id, callback) {

        var user = {};
        if (id == 1) {
            user.id = 1;
            user.kulAdi = "admin";
            user.sifre = "123";            
            callback(user);
        }
        else
           callback(false);
    };

    auth.options.expireSession = 480;
    auth.options.expireCookie = 10;

});

controllers/ws.js

exports.install = function (framework) {
    framework.route('/sshvac', view_homepage);
    framework.websocket('/', sshwebsocket, ['json'], ['ssh'], ['*']);
}

function view_homepage() {
    var self = this;
    self.layout("");
    self.view('sshvac');
}

function sshwebsocket() {
}

controllers/default.js

exports.install = function (framework) {
    framework.route('/', view_homepage, ['authorize']);
    framework.route('/', loginOlmadan);
};

function view_homepage() {
    var self = this;
    self.view('homepage');
}

function loginOlmadan() {
    var self = this;
     self.layout("");
     self.view('loginolmadan');
}

views/sshvac.html

<!DOCTYPE html>
<html>
<head lang="en">
    <meta charset="UTF-8">
    <title>Deneme</title>
    @{js('term.js/term.js')}
</head>
<body style="background-color: black">
<div id="term">

</div>
<script>
    var socket = null;
    socket = new WebSocket('ws://127.0.0.1:8029/', 'ssh');
</script>
</body>
</html>

i'm request "http://127.0.0.1:8029/sshvac"
getting this error;

ReferenceError: req is not defined ReferenceError: req is not defined
    at WebSocketClient.protocol (/var/www/vw_kodlar/client/generator_web/node_modules/total.js/index.js:5:31885)
    at WebSocketClient.prepare (/var/www/vw_kodlar/client/generator_web/node_modules/total.js/index.js:6:914)
    at EventEmitter.Framework._upgrade_continue (/var/www/vw_kodlar/client/generator_web/node_modules/total.js/index.js:3:951)
    at /var/www/vw_kodlar/client/generator_web/node_modules/total.js/index.js:3:809
    at EventEmitter.Users._onAuthorization (/var/www/vw_kodlar/client/generator_web/modules/auth.js:44:9)
    at EventEmitter.authorization [as onAuthorization] (/var/www/vw_kodlar/client/generator_web/modules/auth.js:273:15)
    at EventEmitter.Framework._upgrade_prepare (/var/www/vw_kodlar/client/generator_web/node_modules/total.js/index.js:3:540)
    at EventEmitter.Framework._upgrade (/var/www/vw_kodlar/client/generator_web/node_modules/total.js/index.js:2:31827)
    at Server.<anonymous> (/var/www/vw_kodlar/client/generator_web/node_modules/total.js/index.js:2:21383)
    at Server.EventEmitter.emit (events.js:106:17)

Thanks.

@petersirka
Copy link
Collaborator

Problem is in auth module. Can you send me this module? I'll fix it (or download new total.js and authorization module).
Thanks.

@KiPSOFT-zz
Copy link
Author

I downloaded new auth module and same error.

https://github.com/totaljs/modules/blob/master/auth/v1.00/auth.js

@petersirka
Copy link
Collaborator

And what version of total.js do you use?
I tried to test an example in auth module and it works without any problem.

@KiPSOFT-zz
Copy link
Author

my total.js version v1.6.1

@petersirka
Copy link
Collaborator

Hmmm on v1.6.1 it works.
BTW: I mean this example: https://github.com/totaljs/modules/tree/master/auth/example

@KiPSOFT-zz
Copy link
Author

Problem only websocket request.

@petersirka
Copy link
Collaborator

Aha ... Do you have some example? I'll fix it. Thanks

@KiPSOFT-zz
Copy link
Author

I have example but so complex.

@petersirka
Copy link
Collaborator

OK I understand. Tomorrow I'll create an own example and I'll test it.
Thanks and I'll give a feedback.

@KiPSOFT-zz
Copy link
Author

Thanks peter.

@petersirka
Copy link
Collaborator

Hi @KiPSOFT,
I found a problem in WebSocket routing. I'm surprised.

Please download latest version from GitHub and try to test it. The problem was not in auth module.
Thanks.

@KiPSOFT-zz
Copy link
Author

Hi peter;

I'm download latest version from github and test again. i'm getting same error.i'm prepare simple example. Please check this example how's wrong.

https://github.com/KiPSOFT/totaljswstest

Thanks.

@petersirka
Copy link
Collaborator

Thanks, I found a problem in the framework 👎. I fixed it on GitHub, please download the latest version. Else ... You forgot to add a MODULE('auth').onAuthorization delegate for user authorization.

Give me a feedback.

@KiPSOFT-zz
Copy link
Author

Great working. Thanks peter.

@petersirka
Copy link
Collaborator

Sorry for bugs 💯
Thanks!

@nopol
Copy link

nopol commented Oct 1, 2017

I'm looking for a working example for auth over websockets. Is there some example I'm missing? I tried hard to figure it out with the auth module, but I only managed to get auth working for regular routes, not websockets. i would really appreciate if you could help me out.

@petersirka
Copy link
Collaborator

Hi @dpoellath,
auth in websocket is same as in classic requests. You can use e.g. cookies (but important: it works reading cookies only, not writing --> instead of res argument in F.onAuthorize is socket instance) and authorize flag.

If you will have a problem, contact me. I'll write you a simple example.
Thank you!

@nopol
Copy link

nopol commented Oct 2, 2017

Hi,
I tried it simular to the classic request; installing auth module and adding flag to websocket-route
F.websocket('/{room}/', socket, ['json', 'authorize']);

But I'm sure I oversee something. Perhaps you can add a example.
Perhaps the Auth module is just not capable and I have to write it by myself; that would alos be no problem, but I'll wanted to use the auth-module, because I just wanted to enable both ways.

@petersirka
Copy link
Collaborator

Please try to read this blog (try to understand without auth.js module):
https://blog.totaljs.com/blogs/tutorials/20161114-how-to-create-custom-authorization-mechanism/

Again: If you will have a problem, contact me. I'll write you a simple example.

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

3 participants