Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Open
mclark-ably opened this issue Aug 19, 2024 · 2 comments

Comments

@mclark-ably
Copy link

mclark-ably commented Aug 19, 2024

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

@ttypic
Copy link
Contributor

ttypic commented Aug 19, 2024

I don't think it's a bug. The implementation is definitely non-obvious, but we're not going to change it because it would be a breaking change, and some SDK users might rely on this behavior. With the next major release we are going to get rid of public properties in classes and provide idiomatic builders instead.

@mclark-ably
Copy link
Author

Thanks @ttypic it was just confusing to see that the SDK logged that it was using token auth e.g.

I/System.out(18365): (INFO): Auth(): using token auth with supplied token only

when the client was instantiated like this (this was from a flutter client on Android)

var clientOptions = ably.ClientOptions(
        key: Env.ablyApiKey,
      );

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Development

No branches or pull requests

2 participants