Skip to content

docs: added websocket authentication#8462

Closed
juzhiyuan wants to merge 8 commits into
masterfrom
docs/tutorial-websocket-authentication
Closed

docs: added websocket authentication#8462
juzhiyuan wants to merge 8 commits into
masterfrom
docs/tutorial-websocket-authentication

Conversation

@juzhiyuan

@juzhiyuan juzhiyuan commented Dec 6, 2022

Copy link
Copy Markdown
Member

Description

This tutorial uses key-auth to authenticate before connecting to the upstream WebSocket server.

Rendered Version: https://github.com/apache/apisix/blob/docs/tutorial-websocket-authentication/docs/en/latest/tutorials/websocket-authentication.md

Checklist

  • I have explained the need for this PR and the problem it solves
  • I have explained the changes or the new features added to this PR
  • I have added tests corresponding to this change
  • I have updated the documentation to reflect this change
  • I have verified that this change is backward compatible (If not, please discuss on the APISIX mailing list first)

@juzhiyuan
juzhiyuan requested a review from pottekkat December 6, 2022 08:08
@juzhiyuan
juzhiyuan requested a review from bzp2010 December 6, 2022 08:19

@bzp2010 bzp2010 left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

The content of the article looks good, but there is a problem here.

AFAIK, the browser's WebSocket does not provide an API to allow users to set their own initial request headers. It will affect browser users, but not users who build their own clients.

So for browsers, we'd better switch to using the query parameter as authentication to start a WS connection, otherwise it will be difficult for users to use the authentication plugin provided by APISIX in the browser.

Perhaps it would be better to provide a truly dedicated websocket plugin in the future. 😊


Connect `ws://127.0.0.1:9080/raw` without `key`, APISIX returns `401 Unauthorized` status code.

![Connect without Key](https://static.apiseven.com/2022/12/06/638ef6db9dd4b.png)

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Why is a mosaic used in the picture? 🤔

1. Add one header `apikey` with value `this_is_the_key`;
2. Connect `ws://127.0.0.1:9080/raw` with `key`, it's successfully.

![Connect with key](https://static.apiseven.com/2022/12/06/638efac7c42b6.png)

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

ditto


To establish a WebSocket connection, the client sends a WebSocket **handshake** request, for which the server returns a WebSocket handshake response, see below:

**Client Request**

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Would it be better to change bolds to H3 heading?


Apache APISIX supports [WebSocket](https://en.wikipedia.org/wiki/WebSocket) traffic, but the WebSocket protocol doesn't handle authentication. This article guides you on how to configure authentication for WebSocket connections.

## WebSocket Protocol

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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


When establishing one connection from Client to Server, in the **handshake** phase, APISIX first checks its authentication information, then chooses to proxy this request or deny it directly.

### Pre-requisite

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Suggested change
### Pre-requisite
### Prerequisites


### Key Auth

#### Create one Route

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Suggested change
#### Create one Route
#### Create a Route

}'
```

#### Create one Consumer

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Suggested change
#### Create one Consumer
#### Create a Consumer

Comment on lines +141 to +143
### Note

Other authentication methods are similar to this one.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Please move this note to the top and use the Docusaurus admonition :::note.

Comment on lines +145 to +147
## Reference

1. [Wikipedia - WebSocket](https://en.wikipedia.org/wiki/WebSocket)

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

We do not generally have separate references section. You can just link it inline as you have done in the first sentence. We can remove this section.

@github-actions

Copy link
Copy Markdown

This pull request has been marked as stale due to 60 days of inactivity. It will be closed in 4 weeks if no further activity occurs. If you think that's incorrect or this pull request should instead be reviewed, please simply write any comment. Even if closed, you can still revive the PR at any time or discuss it on the [email protected] list. Thank you for your contributions.

@github-actions github-actions Bot added the stale label Apr 23, 2023
@pottekkat

Copy link
Copy Markdown
Member

I will update this PR because I think @juzhiyuan is busy elsewhere.

@pottekkat

Copy link
Copy Markdown
Member

Opened new PR to add this tutorial. Closing this one.

See: #9369

@pottekkat pottekkat closed this Apr 25, 2023
@membphis
membphis deleted the docs/tutorial-websocket-authentication branch August 2, 2023 10:18
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants