> For the complete documentation index, see [llms.txt](https://ksdaemon.gitbook.io/wampy.js/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://ksdaemon.gitbook.io/wampy.js/api/client-authentication/automatically-chosen-authentication.md).

# Automatically chosen Authentication

If you server provides multiple options for authorization, you can configure wampy.js to automatically choose required authorization flow based on `authmethod` requested by server. For this flow you need to configure next options:

* `authid`. Authentication id to use in challenge
* `authmethods`. Supported authentication methods
* `authextra`. Additional authentication options
* `authPlugins`. Authentication helpers for processing different authmethods challenge flows
* `authMode`. Mode of authorization flow. Should be set to `auto`
* `onChallenge`. onChallenge callback. Is not used when `authMode=auto`

```javascript
import { Wampy } from 'wampy';
import * as wampyCra from 'wampy-cra';
import * as wampyCS from 'wampy-cryptosign';

wampy = new Wampy('wss://wamp.router.url', {
    realm: 'realm1',
    authid: 'patrik',
    authmethods: ['ticket', 'wampcra', 'cryptosign'],
    authextra: {    // User public key for Cryptosign-based Authentication
        pubkey: '545efb0a2192db8d43f118e9bf9aee081466e1ef36c708b96ee6f62dddad9122'
    },
    authPlugins: {
        ticket: (function(userPassword) { return function() { return userPassword; }})(),
        wampcra: wampyCra.sign(userSecret),
        cryptosign: wampyCS.sign(userPrivateKey)
    },
    authMode: 'auto',
    onChallenge: null
});
```
