KSDaemon / wampy.js

Feature-rich lightweight WAMP (Web Application Messaging Protocol) Javascript implementation
https://ksdaemon.gitbook.io/wampy.js/
MIT License
290 stars 41 forks source link

Question: What is the wampy.js equivalent of anonymous `auth/login` and `auth/signup` calls with REST? #156

Closed MichaelJCole closed 2 years ago

MichaelJCole commented 2 years ago

Hi, I'm new to using WAMP protocol and not sure the best place to ask a question.

I'm integrating wampy.js as a Vuex module, in the Quasar framework.

With REST calls, I can

  1. Make an anonymous HTTP requests to get a bearer token
  2. Then "upgrade" my authorization by setting Authorization: Bearer mytoken123 in the client's headers.

For example here is an example Vuex action to register and login a new user

import { api } from 'boot/axios'

export function register ({ commit }, form) {
  return api.post('/auth/register', form)
    .then(response => {
      // configure axios http library to use token on future requests
      api.defaults.headers.common['Authorization'] = 'Bearer ' + response.data.token
      // update vuex "store", so Vue can reactively update app
      commit('login', {token: response.data.token, user: response.data.user})  
    })
}

Is it possible to connect anonymously, pass anonymous messages, then upgrade a WAMP protocol's authentication? Can I do that with the same wampy.js instance?

If yes and no, then my feature request would be wampy.authenticate() or wampy.newSession() that I could use to upgrade the client.

What's the best WAMP way to handle anonymous auth routes like signup/signin/passwordreset/etc?

Thank you!

KSDaemon commented 2 years ago

Hi @MichaelJCole!

I'm integrating wampy.js as a Vuex module, in the Quasar framework.

Cool idea! I love Vue :) Had a look at Quasar too.

Some highlights on WAMP regarding ur questions:

And what about ur questions, but i think some answers you already understand from above.

Is it possible to connect anonymously, pass anonymous messages, then upgrade a WAMP protocol's authentication? No. Thats not possible, as i understand.

At first glance, there are few options how to achieve desired flow:

Of course thats not all. Just first that come to mind. Hope it helps!

MichaelJCole commented 2 years ago

Hi Konstantin, this is very helpful, thank you. I like the idea to use REST for authentication, then authorize a websocket with the token. It's clean.

It makes me think that maybe I can use REST for RPC, and hyper-express for websocket pub/sub built-in.

It's my first websocket app, and I'm not sure what I need yet. Do you have a template for a wamp app? I didn't see any repo on github for "wamp template".

Thank you for your help!