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

Added authToken to kotlin PNConfiguration #305

Merged
merged 4 commits into from
Nov 6, 2024

Conversation

marcin-cebo
Copy link
Contributor

Now it is possible in kotlin for client-side PubNub initialization to provide authToken that will be used in API calls to server. It is also possible in kotlin to override configuration with new token and use it to call particular API e.g. pubnub.publish(randomChannel(), "message").overrideConfiguration {
publishKey = Keys.pubKey
authToken = expectedAuthToken
}.sync()

@@ -25,6 +25,7 @@ class PNConfigurationImpl(
override val publishKey: String = "",
override val secretKey: String = "",
override val authKey: String = "",
override val authToken: String = "", // this property is not used
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

what do you mean it's not used?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

There is no way to set in Java configuration.

internal val tokenManager: TokenManager = TokenManager()

init {
this.setToken(configuration.authToken)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this will overwrite the null value in TokenManager with the default of "" (empty string) from PNConfiguration, which will stop authKey (the deprecated one) from ever being used (because the order in EndpointCore is tokenManager.getToken(), then authKey, and tokenManager.getToken will now never be null)

I think we should make configuration.authToken nullable and null by default (instead of empty string) which I think will solve this. It will be different then other keys (which use empty strings), but IMHO we should over time move all keys to String? = null instead of String = "", it's just not right to use empty strings there.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good catch. I will change the code.

Now it is possible in kotlin for client-side PubNub initialization to provide authToken that will be used in API calls to server.
It is also possible in kotlin to override configuration with new token and use it to call particular API e.g.
pubnub.publish(randomChannel(), "message").overrideConfiguration {
    publishKey = Keys.pubKey
    authToken = expectedAuthToken
}.sync()
@marcin-cebo marcin-cebo merged commit 68c6f1c into master Nov 6, 2024
6 checks passed
@marcin-cebo marcin-cebo deleted the mc/authToken_InPNConfig branch November 6, 2024 10:14
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants