lajosbencz / vue-wamp

AutobahnJS wrapper library fo Vue.js
MIT License
48 stars 13 forks source link

Authentication Support #2

Closed NeilC closed 7 years ago

NeilC commented 7 years ago

Any plans for authentication support?

lajosbencz commented 7 years ago

Do you mean server auth? I didn't find it necessary to create a wrapper for that, you can use the onchallange callback, as per AutobahnJS definition:


Vue.use(VueWamp, {
    url: 'wss://crossbar.io/ws',
    realm: 'default',
    authmethods: ["cookie","wampcra"],
    authid: 'authID',
    max_retries: 3,
    onchallenge: function(session, method, extra) {
        if (method === "wampcra") {
            return autobahn.auth_cra.sign('<my token>', extra.challenge);
        } else {
            throw "don't know how to authenticate using '" + method + "'";
        }
    },
    onopen(session, details) {
        console.debug('WAMP opened: ', session, details);
    },
    onerror(error) {
        console.error(error);
    }
});

What would be your use-case?

oeway commented 7 years ago

@lajosbencz , I am trying to use your library, it's great. A related question, how do you do authentication when you have a single page app?

I mean, I want to get the from a user login dialog, and then trigger the wamp connection, but I can't put this Vue.use in a callback of a button.

So what's your solution? ideally I want to have a function to pass the options and trigger the connection.

Thank you for your nice work.

NeilC commented 7 years ago

@lajosbencz thanks for the example, this answers my question.