autobahn-js icon indicating copy to clipboard operation
autobahn-js copied to clipboard

API docs lack auth reference

Open meejah opened this issue 9 years ago • 11 comments
trafficstars

There is a crossbarexamples example of using WAMP-CRA with AutobahnJS, but the JS API docs don't tell you how to do it

meejah avatar Jul 07 '16 18:07 meejah

+1

erichaus avatar Jul 08 '16 03:07 erichaus

In fact, the API reference for AutobahnJS does not seem to contain any information regarding authentication at all.

ghost avatar Jul 23 '16 20:07 ghost

@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?

erichaus avatar Jul 23 '16 20:07 erichaus

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.

ghost avatar Jul 29 '16 09:07 ghost

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())

erichaus avatar Jul 30 '16 02:07 erichaus

This reminds me why I stopped using CoffeeScript :)

agronholm avatar Jul 30 '16 03:07 agronholm

@agronholm completely subjective... I'd rather use coffeescript all day everyday than vanilla js

erichaus avatar Jul 30 '16 04:07 erichaus

These days I prefer TypeScript.

agronholm avatar Jul 30 '16 04:07 agronholm

+1

@meejah can you share example url?

alexey2baranov avatar Aug 10 '16 10:08 alexey2baranov

@erichonkanen can you please rewrite your code in JS

alexey2baranov avatar Aug 10 '16 11:08 alexey2baranov

https://github.com/crossbario/crossbarexamples/tree/master/authentication/wampcra/static in web/index.html for the JS frontend code.

meejah avatar Aug 10 '16 15:08 meejah