autobahn-js
autobahn-js copied to clipboard
API docs lack auth reference
There is a crossbarexamples example of using WAMP-CRA with AutobahnJS, but the JS API docs don't tell you how to do it
+1
In fact, the API reference for AutobahnJS does not seem to contain any information regarding authentication at all.
@csmcanarney welcome to autobahn! I did end up figuring out how to tie into the auth by looking at source code so what's your question?
Thank you, @erichonkanen! It seems like I'm in the same spot as you: I was able to solve all my issues by looking at the source code.
Here is my coffeescript code that handles creating the autobahn connection optionally with challenge auth...
_getConnection: ->
###
Returns a new or existing Autobahn websocket connection.
@private
@method _getConnection
@return autobahn.Connection
###
token = @get 'session.data.authenticated.token'
connection = =>
onchallenge = (session, method, extra) ->
if method == 'ticket'
if token
return token
else
throw new Error 'Missing required token.'
else
throw new Error 'Invalid method type.'
_config =
initial_retry_delay: 0
max_retries: -1
max_retry_delay: 0
realm: "foo-app"
retry_delay_growth: 0
retry_delay_jitter: 0
url: config.chatHost
# Check if the user is authenticated and if so set the authmethods.
if @get 'session.isAuthenticated'
_config['authid'] = @get 'session.data.authenticated.user.username'
_config['authmethods'] = ['ticket']
_config['onchallenge'] = onchallenge
new autobahn.Connection _config
return @set('connection', @get('connection') or connection())
This reminds me why I stopped using CoffeeScript :)
@agronholm completely subjective... I'd rather use coffeescript all day everyday than vanilla js
These days I prefer TypeScript.
+1
@meejah can you share example url?
@erichonkanen can you please rewrite your code in JS
https://github.com/crossbario/crossbarexamples/tree/master/authentication/wampcra/static in web/index.html for the JS frontend code.