Skip to content

Commit

Permalink
Improve docs
Browse files Browse the repository at this point in the history
  • Loading branch information
robinbraemer committed May 7, 2023
1 parent da374e1 commit a46e9f1
Show file tree
Hide file tree
Showing 15 changed files with 277 additions and 87 deletions.
20 changes: 15 additions & 5 deletions .web/docs/guide/api/authentication.md
Original file line number Diff line number Diff line change
@@ -1,21 +1,31 @@
# Authentication

_How do client, servers and players authenticate to Connect?_
_Clients and [Endpoints](/guide/#connect-endpoints) authenticate to Connect API
with an API token and the Endpoint name so that Connect knows who is making requests
and what permissions you have._

---

If you are using the Connect API through the [Java API provided by Connect Plugin](/guide/api/#java-and-kotlin-client),
you do not write authentication code.

## Required Headers

All requests to the Connect API require the following headers:
- `Connect-Endpoint` - The name of the endpoint the token belongs to.
- `Connect-Token` - The token of the endpoint you are connecting to.

## Unique Server Endpoint Name
## Endpoint Names

Connect has the concept of unique endpoint names to identify your server even after restarts.
The Connect Plugin uses a token file to authenticate that you own an endpoint name in the Connect Network.
Connect has the concept of globally unique **endpoint names** to identify your server even after restarts.
The [Connect Plugin](/guide/#the-connect-plugin) uses a token file to authenticate that you
own an **endpoint name** in the [Connect Network](/guide/#the-connect-network).

```json plugins/connect/token.json
::: code-group
```json [plugins/connect/token.json]
{"token":"T-ozinikukmabrpyzogjjl"}
```
:::

The token and endpoint name have a direct relationship.
If you lose your `token.json` file your endpoint name is lost, and you will have to use a new name.
Expand Down
23 changes: 21 additions & 2 deletions .web/docs/guide/api/examples.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,22 @@
```go
<!--@include: client_example.go -->
# Code Examples

_Code examples are a great way to learn how to use the Connect API in different languages._

::: code-group

[//]: # (TODO move docs to connect-java and include java examples here)

```java [Connect Plugin <VPBadge>Java</VPBadge>]
TODO CHECK BACK LATER
<!--@include: javaconnectplugin/src/main/java/com/minekube/connect/example/ExamplePlugin.java -->
```

```go [Buf Remote Package <VPBadge>Golang</VPBadge>]
<!--@include: goexample/example_test.go -->
```

```md [Other languages]
Checkout https://buf.build/minekube/connect/assets
```

:::
110 changes: 110 additions & 0 deletions .web/docs/guide/api/goexample/example_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,110 @@
package goexample

import (
"context"
"net/http"

minekube "buf.build/gen/go/minekube/connect/bufbuild/connect-go/minekube/connect/v1alpha1/connectv1alpha1connect"
connectpb "buf.build/gen/go/minekube/connect/protocolbuffers/go/minekube/connect/v1alpha1"

// You can read more about Buf's Connect for Go here https://connect.build/docs/go
"github.com/bufbuild/connect-go"
)

const (
// This is the official Connect API endpoint.
baseURL = "https://connect-api.minekube.com"

// These are the headers you need to set to authenticate with the Connect API.
endpointHeader = "Connect-Endpoint"
tokenHeader = "Connect-Token"
)

// ExampleClient_ListEndpoints shows how to list endpoints you have access to.
// It uses the default http.Client and sets the endpoint and token headers
// manually.
func ExampleClient_ListEndpoints() {
// Set up the client.
client := minekube.NewConnectServiceClient(http.DefaultClient, baseURL)

// Set up a request to list endpoints you have access to.
ctx := context.TODO()
req := connect.NewRequest(&connectpb.ListEndpointsRequest{})
req.Header().Set(endpointHeader, "my-endpoint")
req.Header().Set(tokenHeader, "my-token")

// Fetch all endpoints until the server returns an empty page.
for {
// Send the request.
res, err := client.ListEndpoints(ctx, req)
if err != nil {
panic(err)
}

// Print the endpoints.
for _, endpoint := range res.Msg.GetEndpoints() {
// Do something with the endpoint.
println(endpoint)
}

// Prepare the next request.
req.Msg.PageToken = res.Msg.GetNextPageToken()
if req.Msg.PageToken == "" {
// No more pages.
break
}
}
}

// ExampleClient_ListEndpoints_WithHeadersTransport shows how to connect players
// to an endpoint. It uses a custom http.Client that adds the endpoint and token
// headers to every request automatically.
func ExampleClient_ConnectEndpoint_WithHeadersTransport() {
// Set up the client.
httpClient := &http.Client{Transport: &headersTransport{
headers: map[string]string{
endpointHeader: "my-endpoint",
tokenHeader: "my-token",
},
}}
client := minekube.NewConnectServiceClient(httpClient, baseURL)

// Set up a request to connect a players to an endpoint you have access to.
ctx := context.TODO()
req := connect.NewRequest(&connectpb.ConnectEndpointRequest{
Endpoint: "my-endpoint",
Players: []string{
// example player uuids,
// the players must be online and on another endpoint you have access to.
"11111111-1111-1111-1111-111111111111",
"22222222-2222-2222-2222-222222222222",
"33333333-3333-3333-3333-333333333333",
},
})

// Send the request.
_, err := client.ConnectEndpoint(ctx, req)
if err != nil {
panic(err)
}
}

// headersTransport is a http.RoundTripper that adds headers to requests
// before sending them so that we don't have to add them to every request
// manually.
type headersTransport struct {
headers map[string]string
base http.RoundTripper
}

// RoundTrip implements http.RoundTripper. It adds the headers to the request.
func (h *headersTransport) RoundTrip(req *http.Request) (*http.Response, error) {
for k, v := range h.headers {
req.Header.Add(k, v)
}
base := h.base
if base == nil {
base = http.DefaultTransport
}
return base.RoundTrip(req)
}
10 changes: 10 additions & 0 deletions .web/docs/guide/api/goexample/go.mod
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
module goexample

go 1.20

require (
buf.build/gen/go/minekube/connect/bufbuild/connect-go v1.7.0-20230426152538-ad9b44e4a050.1 // indirect
buf.build/gen/go/minekube/connect/protocolbuffers/go v1.30.0-20230426152538-ad9b44e4a050.1 // indirect
github.com/bufbuild/connect-go v1.7.0 // indirect
google.golang.org/protobuf v1.30.0 // indirect
)
12 changes: 12 additions & 0 deletions .web/docs/guide/api/goexample/go.sum
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
buf.build/gen/go/minekube/connect/bufbuild/connect-go v1.7.0-20230426152538-ad9b44e4a050.1 h1:4LWolQseUun8p0kZC8nN9kj7M1dQlPJjv61lkdKt/B0=
buf.build/gen/go/minekube/connect/bufbuild/connect-go v1.7.0-20230426152538-ad9b44e4a050.1/go.mod h1:5x7C3tv7MLXHBkeolbWEG2wf7vwyjeaE+FgdTjmP0HM=
buf.build/gen/go/minekube/connect/protocolbuffers/go v1.30.0-20230426152538-ad9b44e4a050.1 h1:bUDOTKeRKFVO0I+pYYs3W9QgbKU55tlRt1n88ZAvN2w=
buf.build/gen/go/minekube/connect/protocolbuffers/go v1.30.0-20230426152538-ad9b44e4a050.1/go.mod h1:pY8nIBqtBexIBlNoBXG+3gviKiC4C9QLAIJ3FHwXUDs=
github.com/bufbuild/connect-go v1.7.0 h1:MGp82v7SCza+3RhsVhV7aMikwxvI3ZfD72YiGt8FYJo=
github.com/bufbuild/connect-go v1.7.0/go.mod h1:GmMJYR6orFqD0Y6ZgX8pwQ8j9baizDrIQMm1/a6LnHk=
github.com/golang/protobuf v1.5.0/go.mod h1:FsONVRAS9T7sI+LIUmWTfcYkHO4aIWwzhcaSAoJOfIk=
github.com/google/go-cmp v0.5.5/go.mod h1:v8dTdLbMG2kIc/vJvl+f65V22dbkXbowE6jgT/gNBxE=
golang.org/x/xerrors v0.0.0-20191204190536-9bdfabe68543/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0=
google.golang.org/protobuf v1.26.0-rc.1/go.mod h1:jlhhOSvTdKEhbULTjvd4ARK9grFBp09yW+WbY/TyQbw=
google.golang.org/protobuf v1.30.0 h1:kPPoIgf3TsEvrm0PFe15JQ+570QVxYzEvvHqChK+cng=
google.golang.org/protobuf v1.30.0/go.mod h1:HV8QOd/L58Z+nl8r43ehVNZIU/HEI6OcFqwMG9pJV4I=
73 changes: 66 additions & 7 deletions .web/docs/guide/api/index.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,14 +8,73 @@ through the Connect API._

## Getting started

You can quickly get started with [Buf Remote Packages](https://buf.build/minekube/connect/assets/main)
that provide client libraries for many programming languages for the Connect API.
- [Java and Kotlin client](#java-and-kotlin-client)
- [Golang and other language clients](#golang-and-other-language-clients)

## Java and Kotlin client

You can access the Connect API through the official Java/Kotlin client
provided by the [Connect Plugin](https://github.com/minekube/connect-java).

Simply add the `connect-java:api` dependency to your project using Gradle or Maven with
[Jitpack](https://jitpack.io/#minekube/connect-java).

::: code-group

```kotlin [build.gradle.kts <VPBadge>Gradle Kotlin</VPBadge>]
repositories {
maven("https://jitpack.io")
}

dependencies {
api("com.github.minekube.connect-java:api:latest")
}
```

```groovy [build.gradle <VPBadge>Gradle Groovy</VPBadge>]
repositories {
maven { url 'https://jitpack.io' }
}
Read further to learn how to use **Java or Kotlin**.
dependencies {
api 'com.github.minekube.connect-java:api:latest'
}
```

```xml [pom.xml <VPBadge>Maven</VPBadge>]

<repositories>
<repository>
<id>jitpack.io</id>
<url>https://jitpack.io</url>
</repository>
</repositories>

<dependencies>
<dependency>
<groupId>com.github.minekube.connect-java</groupId>
<artifactId>api</artifactId>
<version>latest</version>
<scope>provided</scope>
</dependency>
</dependencies>
```

:::


## Golang and other language clients

You can quickly get started with
[Buf Remote Packages](https://buf.build/minekube/connect/assets/main)
that provide client libraries for many programming languages for the Connect API.

## Authentication
For example, to install the Go Connect API client:

Using the Connect API requires authentication with a valid API token
so that Connect knows who is making requests and what permissions you have.
```shell
$ go get github.com/bufbuild/connect-go@latest
$ go get buf.build/gen/go/minekube/connect/bufbuild/connect-go@latest
$ go get buf.build/gen/go/minekube/connect/protocolbuffers/go@latest
```

Go to the [Authentication guide](/guide/api/authentication).
[![Buf Remote Packages](/images/bufbuild-assets.png)](https://buf.build/minekube/connect/assets/main)
2 changes: 2 additions & 0 deletions .web/docs/guide/downloads.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
# Downloads

_Downloading Connect Plugin is a breeze,
Just a few clicks and you'll be pleased!_

<!--@include: ./includes/downloads.md-->
50 changes: 20 additions & 30 deletions .web/docs/guide/includes/downloads.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,51 +4,41 @@ The installation steps are the same as for every other Minecraft plugin
_(Download jar, put in plugins folder, start server)_. The only difference is that
you can download the Connect plugin right here, instead of SpigotMC.


| Downloads | | |
|--------------------------------------------------------------------------------------------------------|----------------------------------------------------------------------------------------------------|----------------------------------------------------------------------------------------------------|
| [Spigot/PaperMC](https://github.com/minekube/connect-java/releases/download/latest/connect-spigot.jar) | [Velocity](https://github.com/minekube/connect-java/releases/download/latest/connect-velocity.jar) | [BungeeCord](https://github.com/minekube/connect-java/releases/download/latest/connect-bungee.jar) |
| <VPBadge>Spigot/PaperMC Plugin</VPBadge> | <VPBadge>Velocity Plugin</VPBadge> | <VPBadge>BungeeCord Plugin</VPBadge> |
|------------------------------------------------------------------------------------------------------------|----------------------------------------------------------------------------------------------------------------|------------------------------------------------------------------------------------------------------------|
| [connect-spigot.jar](https://github.com/minekube/connect-java/releases/download/latest/connect-spigot.jar) | [connect-velocity.jar](https://github.com/minekube/connect-java/releases/download/latest/connect-velocity.jar) | [connect-bungee.jar](https://github.com/minekube/connect-java/releases/download/latest/connect-bungee.jar) |

Ready to experience Minekube Connect? Download the latest stable release for your platform!
:point_up_2:

[_What does the Connect Plugin do?_](/guide/#the-connect-plugin)

## Disabling `enforce secure player profiles`

::: details Why is this necessary?
## Disabling "enforce secure player profiles" <VPBadge type='danger'>Required</VPBadge>

Since Minecraft 1.19 the `enforce-secure-profile` property was introduced.
Players joining through the Connect network to your server won't be able to join if this setting
Players joining through the [Connect Network](/guide/#the-connect-network) to your server won't be able to join if this setting
is enabled. It is safe to disable this setting as it only affects chat messages.
F

:::

::: warning Spigot/PaperMC's `server.properties`
::: code-group

You need to disable `enforce-secure-profile` property
```properties [<VPBadge type='none'>Spigot/PaperMC</VPBadge> server.properties]
enforce-secure-profile=false

```txt
...
enable-rcon=false
online-mode=true // [!code focus]
enforce-secure-profile=false // [!code focus]
enable-status=true
...
# If you disable online-mode, then enforce-secure-profile has no effect
online-mode=true
```

or simply disable `online-mode` which also disables `enforce-secure-profile`
```toml [<VPBadge type='none'>Velocity</VPBadge> velocity.toml]
force-key-authentication=false

```txt
...
enable-rcon=false
online-mode=false // [!code focus]
enforce-secure-profile=true
...
# If you disable online-mode, then force-key-authentication has no effect
online-mode=true
```

:::
```yaml [<VPBadge type='none'>BungeeCord</VPBadge> config.yml]
enforce_secure_profile=false


- If using Velocity set `force-key-authentication` to `false` in `velocity.toml`.
- If using BungeeCord set `enforce_secure_profile` to `false` in `config.yml`.
# If you disable online-mode, then enforce-secure-profile has no effect
online_mode=true
```
9 changes: 5 additions & 4 deletions .web/docs/guide/includes/joining.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,14 +5,15 @@ the domain players can join the server with.
If you leave this field empty, Connect will use a temporary random endpoint name
for your server provided by the [Random Name Service](https://randomname.minekube.net/).

You can always update that endpoint name in `plugins/connect/config.yml`
You can always update that endpoint name in the config:

```yaml
::: code-group
```yaml [plugins/connect/config.yml]
endpoint: your-server-name
```
:::
> The environment variable `CONNECT_ENDPOINT` takes precedence over the endpoint value
> in the configuration file.
> The environment variable `CONNECT_ENDPOINT` takes precedence over the configuration file.

### Joining with free provided Public Domain

Expand Down
Loading

0 comments on commit a46e9f1

Please sign in to comment.