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

[ECO-4550] Fix JWT authentication #669

Merged
merged 15 commits into from
Sep 12, 2024
Merged

[ECO-4550] Fix JWT authentication #669

merged 15 commits into from
Sep 12, 2024

Conversation

sacOO7
Copy link
Collaborator

@sacOO7 sacOO7 commented Sep 4, 2024

Summary by CodeRabbit

  • Documentation

    • Enhanced the authentication section of the README to provide detailed guidance on using ably.NewREST with ABLY_KEY and implementing token authentication for both server and client-side applications.
    • Clarified the creation of secure endpoints for token generation and included practical examples for managing JWT tokens effectively.
  • New Features

    • Introduced new methods for JWT generation in the Sandbox, allowing for configurable authentication parameters.
  • Tests

    • Expanded test coverage for JWT authentication scenarios, including successful and erroneous handling of tokens.
    • Implemented a test for reauthorizing with a JWT token, ensuring robust connection state management.

@sacOO7 sacOO7 changed the base branch from main to feature/server-initiated-auth September 4, 2024 11:47
Copy link
Contributor

coderabbitai bot commented Sep 4, 2024

Walkthrough

The changes introduce comprehensive updates to the authentication mechanisms, particularly focusing on JWT (JSON Web Token) support. Enhancements include modifications to the documentation, code functions, and integration tests, ensuring secure server-side authentication, improved handling of different token types, and expanded test coverage for various authentication scenarios.

Changes

Files Change Summary
README.md Updated authentication documentation emphasizing secure handling of ABLY_KEY and JWT usage.
ably/auth.go Modified requestAuthURL to handle both "text/plain" and "application/jwt" MIME types.
ably/auth_integration_test.go Added new test cases for JWT retrieval, authentication via URL, callback usage, and error handling.
ably/realtime_conn_spec_integration_test.go Implemented test for reauthorizing with JWT tokens, validating connection state transitions.
ablytest/sandbox.go Introduced CREATE_JWT_URL, GetJwtAuthParams, and CreateJwt methods for JWT generation.

Assessment against linked issues

Objective Addressed Explanation
Support for JWT authentication (Issue #569)
Implement tests for JWT handling (Issue #569)
Address known limitations regarding JWT (Issue #569)

Possibly related PRs

Poem

In the meadow, I hop with glee,
JWTs are here, oh what a spree! 🐇✨
Secure and safe, our tokens dance,
With Ably's magic, we take a chance.
Authentication's bright, a joyful song,
In this new world, we all belong! 🌼


Recent review details

Configuration used: CodeRabbit UI
Review profile: CHILL

Commits

Files that changed from the base of the PR and between 13bfc96 and ce1c6fb.

Files selected for processing (1)
  • README.md (1 hunks)
Additional context used
LanguageTool
README.md

[uncategorized] ~331-~331: Possible missing preposition found.
Context: ...bly.com/docs/auth) for more information types of auth and it's server/client-side usa...

(AI_HYDRA_LEO_MISSING_TO)


[uncategorized] ~331-~331: Use a comma before ‘and’ if it connects two independent clauses (unless they are closely connected and short).
Context: ...auth) for more information types of auth and it's server/client-side usage. ```go r...

(COMMA_COMPOUND_SENTENCE)

Additional comments not posted (4)
README.md (4)

329-346: The code segment looks good, but consider improving the surrounding text.

The code segment provides a useful example of initializing ably.NewREST using ABLY_KEY and creating a token request endpoint using a Gin server. However, as discussed in the past review comments, it would be better to link to the relevant sections of the official Ably documentation instead of repeating the information in the README.

Consider updating the surrounding text to something like:

ably-go is typically used in a server-side environment where it is recommended to use an API key for authentication (for further details on why, see Available authentication mechanisms).

ably-go can be used to issue tokens to clients as outlined in the Ably Tokens documentation.

Tools
LanguageTool

[uncategorized] ~331-~331: Possible missing preposition found.
Context: ...bly.com/docs/auth) for more information types of auth and it's server/client-side usa...

(AI_HYDRA_LEO_MISSING_TO)


[uncategorized] ~331-~331: Use a comma before ‘and’ if it connects two independent clauses (unless they are closely connected and short).
Context: ...auth) for more information types of auth and it's server/client-side usage. ```go r...

(COMMA_COMPOUND_SENTENCE)


348-349: LGTM!

The information provided about setting the content type header when using WithAuthURL client option for JWT tokens is correct and useful.


350-367: LGTM!

The code segment provides a useful example of using WithAuthCallback client option to fetch a token from a server and decode it based on the response. The implementation looks correct.


369-377: LGTM!

The code segment provides a useful example of using WithAuthCallback client option to fetch a JWT token from a server. The implementation looks correct.


Thank you for using CodeRabbit. We offer it for free to the OSS community and would appreciate your support in helping us grow. If you find it useful, would you consider giving us a shout-out on your favorite social media?

Share
Tips

Chat

There are 3 ways to chat with CodeRabbit:

  • Review comments: Directly reply to a review comment made by CodeRabbit. Example:
    • I pushed a fix in commit <commit_id>.
    • Generate unit testing code for this file.
    • Open a follow-up GitHub issue for this discussion.
  • Files and specific lines of code (under the "Files changed" tab): Tag @coderabbitai in a new review comment at the desired location with your query. Examples:
    • @coderabbitai generate unit testing code for this file.
    • @coderabbitai modularize this function.
  • PR comments: Tag @coderabbitai in a new PR comment to ask questions about the PR branch. For the best results, please provide a very specific query, as very limited context is provided in this mode. Examples:
    • @coderabbitai generate interesting stats about this repository and render them as a table.
    • @coderabbitai show all the console.log statements in this repository.
    • @coderabbitai read src/utils.ts and generate unit testing code.
    • @coderabbitai read the files in the src/scheduler package and generate a class diagram using mermaid and a README in the markdown format.
    • @coderabbitai help me debug CodeRabbit configuration file.

Note: Be mindful of the bot's finite context window. It's strongly recommended to break down tasks such as reading entire modules into smaller chunks. For a focused discussion, use review comments to chat about specific files and their changes, instead of using the PR comments.

CodeRabbit Commands (Invoked using PR comments)

  • @coderabbitai pause to pause the reviews on a PR.
  • @coderabbitai resume to resume the paused reviews.
  • @coderabbitai review to trigger an incremental review. This is useful when automatic reviews are disabled for the repository.
  • @coderabbitai full review to do a full review from scratch and review all the files again.
  • @coderabbitai summary to regenerate the summary of the PR.
  • @coderabbitai resolve resolve all the CodeRabbit review comments.
  • @coderabbitai configuration to show the current CodeRabbit configuration for the repository.
  • @coderabbitai help to get help.

Other keywords and placeholders

  • Add @coderabbitai ignore anywhere in the PR description to prevent this PR from being reviewed.
  • Add @coderabbitai summary to generate the high-level summary at a specific location in the PR description.
  • Add @coderabbitai anywhere in the PR title to generate the title automatically.

CodeRabbit Configuration File (.coderabbit.yaml)

  • You can programmatically configure CodeRabbit by adding a .coderabbit.yaml file to the root of your repository.
  • Please see the configuration documentation for more information.
  • If your editor has YAML language server enabled, you can add the path at the top of this file to enable auto-completion and validation: # yaml-language-server: $schema=https://coderabbit.ai/integrations/schema.v2.json

Documentation and Community

  • Visit our Documentation for detailed information on how to use CodeRabbit.
  • Join our Discord Community to get help, request features, and share feedback.
  • Follow us on X/Twitter for updates and announcements.

@sacOO7 sacOO7 mentioned this pull request Sep 4, 2024
@github-actions github-actions bot temporarily deployed to staging/pull/669/features September 4, 2024 11:48 Inactive
@github-actions github-actions bot temporarily deployed to staging/pull/669/godoc September 4, 2024 11:48 Inactive
@sacOO7 sacOO7 requested review from lmars, amnonbc and ttypic September 4, 2024 11:56
@github-actions github-actions bot temporarily deployed to staging/pull/669/godoc September 4, 2024 13:18 Inactive
@github-actions github-actions bot temporarily deployed to staging/pull/669/features September 4, 2024 13:18 Inactive
@sacOO7 sacOO7 force-pushed the fix/jwt-authentication branch from 5234901 to 52e16c3 Compare September 4, 2024 14:04
@github-actions github-actions bot temporarily deployed to staging/pull/669/godoc September 4, 2024 14:05 Inactive
@github-actions github-actions bot temporarily deployed to staging/pull/669/features September 4, 2024 14:05 Inactive
@github-actions github-actions bot temporarily deployed to staging/pull/669/godoc September 4, 2024 17:10 Inactive
@github-actions github-actions bot temporarily deployed to staging/pull/669/features September 4, 2024 17:10 Inactive
@github-actions github-actions bot temporarily deployed to staging/pull/669/features September 4, 2024 17:13 Inactive
@github-actions github-actions bot temporarily deployed to staging/pull/669/godoc September 4, 2024 17:13 Inactive
@sacOO7 sacOO7 force-pushed the fix/jwt-authentication branch from 624a83c to 1ffeb0f Compare September 5, 2024 05:55
@github-actions github-actions bot temporarily deployed to staging/pull/669/features September 5, 2024 05:56 Inactive
@github-actions github-actions bot temporarily deployed to staging/pull/669/godoc September 5, 2024 05:56 Inactive
@github-actions github-actions bot temporarily deployed to staging/pull/669/godoc September 5, 2024 09:47 Inactive
Copy link
Contributor

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 0

Review details

Configuration used: CodeRabbit UI
Review profile: CHILL

Commits

Files that changed from the base of the PR and between 1ca24af and d9d1f53.

Files selected for processing (1)
  • ably/auth_integration_test.go (2 hunks)
Files skipped from review as they are similar to previous changes (1)
  • ably/auth_integration_test.go

@github-actions github-actions bot temporarily deployed to staging/pull/669/features September 7, 2024 17:28 Inactive
@github-actions github-actions bot temporarily deployed to staging/pull/669/godoc September 7, 2024 17:28 Inactive
Copy link
Contributor

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 0

Review details

Configuration used: CodeRabbit UI
Review profile: CHILL

Commits

Files that changed from the base of the PR and between d9d1f53 and b17ced2.

Files selected for processing (1)
  • ably/auth_integration_test.go (2 hunks)
Files skipped from review as they are similar to previous changes (1)
  • ably/auth_integration_test.go

@sacOO7
Copy link
Collaborator Author

sacOO7 commented Sep 7, 2024

@coderabbitai resolve

Copy link
Contributor

coderabbitai bot commented Sep 7, 2024

Actions performed

Comments resolved.

@github-actions github-actions bot temporarily deployed to staging/pull/669/godoc September 9, 2024 08:04 Inactive
@github-actions github-actions bot temporarily deployed to staging/pull/669/features September 9, 2024 08:04 Inactive
Copy link
Contributor

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 0

Outside diff range, codebase verification and nitpick comments (2)
README.md (2)

331-331: Consider using a hyphen for compound adjectives.

For clarity and grammatical correctness, consider changing "server-side applications" to "server-side applications" and "client side applications" to "client-side applications" to form proper compound adjectives.

Tools
LanguageTool

[uncategorized] ~331-~331: If this is a compound adjective that modifies the following noun, use a hyphen.
Context: ...cation on server-side applications. For client side applications, you should use token auth...

(EN_COMPOUND_ADJECTIVE_INTERNAL)


349-349: Avoid adverb repetition.

The phrase "as per official ably JWT doc" repeats the adverb "officially." Consider rephrasing to avoid redundancy and enhance readability.

Tools
LanguageTool

[style] ~349-~349: This adverb was used twice in the sentence. Consider removing one of them or replacing them with a synonym.
Context: ...igned using ABLY_KEY as per [official ably JWT doc](https://ably.com/tutorials/jwt...

(ADVERB_REPETITION_PREMIUM)

Review details

Configuration used: CodeRabbit UI
Review profile: CHILL

Commits

Files that changed from the base of the PR and between b17ced2 and a59b9d6.

Files selected for processing (1)
  • README.md (2 hunks)
Additional context used
LanguageTool
README.md

[uncategorized] ~331-~331: If this is a compound adjective that modifies the following noun, use a hyphen.
Context: ...cation on server-side applications. For client side applications, you should use token auth...

(EN_COMPOUND_ADJECTIVE_INTERNAL)


[style] ~349-~349: This adverb was used twice in the sentence. Consider removing one of them or replacing them with a synonym.
Context: ...igned using ABLY_KEY as per [official ably JWT doc](https://ably.com/tutorials/jwt...

(ADVERB_REPETITION_PREMIUM)

Additional comments not posted (1)
README.md (1)

331-381: Enhanced Authentication Documentation Review.

The updated sections from lines 331 to 381 provide a comprehensive overview of using ABLY_KEY for server-side applications and detail the process for token authentication, including JWT handling. These changes align well with the PR's objectives to enhance JWT support and improve security documentation.

  • The use of ABLY_KEY is clearly discouraged for client-side applications, which is a crucial security best practice.
  • The examples provided for token generation and handling JWT tokens are practical and enhance the usability of the documentation.

Overall, these updates significantly improve the clarity and security of the authentication process in the README, ensuring that developers have a clear guide on implementing authentication securely.

Tools
LanguageTool

[uncategorized] ~331-~331: If this is a compound adjective that modifies the following noun, use a hyphen.
Context: ...cation on server-side applications. For client side applications, you should use token auth...

(EN_COMPOUND_ADJECTIVE_INTERNAL)


[style] ~349-~349: This adverb was used twice in the sentence. Consider removing one of them or replacing them with a synonym.
Context: ...igned using ABLY_KEY as per [official ably JWT doc](https://ably.com/tutorials/jwt...

(ADVERB_REPETITION_PREMIUM)

@sacOO7 sacOO7 requested a review from AndyTWF September 9, 2024 08:08
@sacOO7 sacOO7 force-pushed the fix/jwt-authentication branch from a59b9d6 to 13bfc96 Compare September 9, 2024 08:10
@github-actions github-actions bot temporarily deployed to staging/pull/669/features September 9, 2024 08:11 Inactive
@github-actions github-actions bot temporarily deployed to staging/pull/669/godoc September 9, 2024 08:11 Inactive
Copy link
Contributor

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 0

Outside diff range, codebase verification and nitpick comments (2)
README.md (2)

331-331: Consider using a hyphen for compound adjectives.

For clarity and grammatical correctness, consider using a hyphen in "client-side applications" to form a compound adjective.

- For client side applications, you should use token authentication to prevent your API key from being shared.
+ For client-side applications, you should use token authentication to prevent your API key from being shared.
Tools
LanguageTool

[uncategorized] ~331-~331: If this is a compound adjective that modifies the following noun, use a hyphen.
Context: ...cation on server-side applications. For client side applications, you should use token auth...

(EN_COMPOUND_ADJECTIVE_INTERNAL)


349-349: Avoid adverb repetition.

The phrase "as per [official ably JWT doc]" repeats the adverb "officially" which might be redundant. Consider rephrasing for clarity.

- You can also return JWT string token signed using `ABLY_KEY` as per [official ably JWT doc](https://ably.com/tutorials/jwt-authentication).
+ You can also return JWT string token signed using `ABLY_KEY` according to the [official Ably JWT documentation](https://ably.com/tutorials/jwt-authentication).
Tools
LanguageTool

[style] ~349-~349: This adverb was used twice in the sentence. Consider removing one of them or replacing them with a synonym.
Context: ...igned using ABLY_KEY as per [official ably JWT doc](https://ably.com/tutorials/jwt...

(ADVERB_REPETITION_PREMIUM)

Review details

Configuration used: CodeRabbit UI
Review profile: CHILL

Commits

Files that changed from the base of the PR and between a59b9d6 and 13bfc96.

Files selected for processing (1)
  • README.md (2 hunks)
Additional context used
LanguageTool
README.md

[uncategorized] ~331-~331: If this is a compound adjective that modifies the following noun, use a hyphen.
Context: ...cation on server-side applications. For client side applications, you should use token auth...

(EN_COMPOUND_ADJECTIVE_INTERNAL)


[style] ~349-~349: This adverb was used twice in the sentence. Consider removing one of them or replacing them with a synonym.
Context: ...igned using ABLY_KEY as per [official ably JWT doc](https://ably.com/tutorials/jwt...

(ADVERB_REPETITION_PREMIUM)

@sacOO7 sacOO7 force-pushed the fix/jwt-authentication branch from 13bfc96 to 4926542 Compare September 9, 2024 08:16
@github-actions github-actions bot temporarily deployed to staging/pull/669/godoc September 9, 2024 08:17 Inactive
@github-actions github-actions bot temporarily deployed to staging/pull/669/features September 9, 2024 08:17 Inactive
@sacOO7 sacOO7 requested a review from amnonbc September 9, 2024 12:33
Copy link
Contributor

@amnonbc amnonbc left a comment

Choose a reason for hiding this comment

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

LGTM

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

Successfully merging this pull request may close these issues.

JWT (JSON Web Token) authentication
4 participants