Skip to content

accessToken query param used when AblyRealtime is instantiated with an incorrect API key #1026

@mclark-ably

Description

@mclark-ably

Bit of a minor but found a strange behaviour when using ably-java

if the following is used (with an incorrect API key) :

ClientOptions options = new ClientOptions("1234");
options.logLevel = Log.VERBOSE;
AblyRealtime realtime = new AblyRealtime(options); 

The request is made to wss://realtime.ably.io:443/?accessToken=1234 and the error is trying to be made with a token
(ERROR): io.ably.lib.transport.ConnectionManager: onMessage(): ERROR message received; message = Invalid accessToken in request: 1234. (See https://help.ably.io/error/40005 for help.); code = 40005

However with the following:

ClientOptions options = new ClientOptions();
options.logLevel = Log.VERBOSE;
options.key = "12234";
AblyRealtime realtime = new AblyRealtime(options);

The request is made to wss://realtime.ably.io:443/?key=12234 and the error is (ERROR): io.ably.lib.transport.ConnectionManager: onMessage(): ERROR message received; message = Invalid key in request: 12234. (See https://help.ably.io/error/40005 for help.); code = 40005

looks like it comes from the logic in the AuthOptions constructor which sets the client to use token auth if no colon is found in the passed in string

public AuthOptions(String key) throws AblyException {

┆Issue is synchronized with this Jira Task by Unito

Metadata

Metadata

Assignees

No one assigned

    Labels

    code-qualityAffects the developer experience when working in our codebase.

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions