Commit 293dc941 authored by Chris Molozian's avatar Chris Molozian
Browse files

Add authentication strategies to service definition. (#200)

parent 8bddbe84
Loading
Loading
Loading
Loading
+1 −0
Original line number Diff line number Diff line
@@ -29,6 +29,7 @@ This release brings a large number of changes and new features to the server. It
- Startup messages are more concise.
- Log messages have been updated to be more useful in development.
- Stdlib for the code runtime uses "snake_case" consistently across variables and function names.
- The base image for our Docker images now uses Alpine Linux.

### Fixed
- Build dependencies are now vendored and build system is simplified.
+12 −10
Original line number Diff line number Diff line
@@ -57,11 +57,9 @@ You can run the servers with native binaries for your platform.

When connected you'll see server output which describes all settings the server uses for [configuration](https://heroiclabs.com/docs/install-configuration).

```shell
{"level":"info","ts":"2018-04-29T10:14:41.249+0100","msg":"Node","name":"nakama","version":"2.0.0+7e18b09","runtime":"go1.10.1","cpu":4}
{"level":"info","ts":"2018-04-29T10:14:41.249+0100","msg":"Database connections","dsns":["root@127.0.0.1:26257"]}
...
```
> {"level":"info","ts":"2018-04-29T10:14:41.249+0100","msg":"Node","name":"nakama","version":"2.0.0+7e18b09","runtime":"go1.10.1","cpu":4}
> {"level":"info","ts":"2018-04-29T10:14:41.249+0100","msg":"Database connections","dsns":["root@127.0.0.1:26257"]}
> ...

## Usage

@@ -70,13 +68,17 @@ Nakama supports a variety of protocols optimized for various gameplay or app use
For example with the REST API to authenticate a user account with a custom identifier.

```shell
curl "http://127.0.0.1:7350/v2/account/authenticate/custom?username=allmight&create=true" --user 'defaultkey:' --data '{"id": "someuniqueidentifier"}'

{
    "token":"eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJleHAiOjE1MjQ5OTU2NDksInVpZCI6Ijk5Y2Q1YzUyLWE5ODgtNGI2NC04YThhLTVmMTM5YTg4MTgxMiIsInVzbiI6InhBb1RxTUVSdFgifQ.-3_rXNYx3Q4jKuS7RkxeMWBzMNAm0vl93QxzRI8p_IY"
}
curl "http://127.0.0.1:7350/v2/account/authenticate/custom?create=true&username=allmight" \
  --user "defaultkey:" \
  --data '{"id": "someuniqueidentifier"}'
```

Response:

> {
>     "token":"eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJleHAiOjE1MjQ5OTU2NDksInVpZCI6Ijk5Y2Q1YzUyLWE5ODgtNGI2NC04YThhLTVmMTM5YTg4MTgxMiIsInVzbiI6InhBb1RxTUVSdFgifQ.-3_rXNYx3Q4jKuS7RkxeMWBzMNAm0vl93QxzRI8p_IY"
> }

There's a number of official [client libraries](https://github.com/heroiclabs) available on GitHub with [documentation](https://heroiclabs.com/docs). The current platform/language support includes: .NET (in C#), Unity engine, JavaScript, Java (with Android), Unreal engine, and Swift (with iOS). If you'd like to contribute a client or request one let us know.

## Deployment
+278 −272

File changed.

Preview size limit exceeded, changes collapsed.

+101 −28
Original line number Diff line number Diff line
@@ -35,33 +35,6 @@ option csharp_namespace = "Nakama";

option objc_class_prefix = "NKPB";

// NOTE: we will no longer return server time.
// NOTE: we will implement a logout message later.
// NOTE: unlink will behave exactly like link/register now.
// NOTE: last_online_at is now online in user messages.
// NOTE: metadata will not be modifiable in user, self, and group messages.
// NOTE: group state will become an enum. Join will now be JOIN_REQUEST.
// NOTE: topic will now be known as channel.
// NOTE: we will flatten realtime messages to be simpler as JSON inputs.
// NOTE: remove bucket field and concept from server.
// NOTE: remove expires_at field and concept from server.
// NOTE: leaderboard sort field will become an enum.
// NOTE: we will use plural to describe batched results and list to describe results with a cursor.
// NOTE: TLeaderboardsRecordsFetch should return the current user's records from 1+ leaderboard ids.
// NOTE: add conditional get support to storage fetch operations.
// NOTE: record field in storage objects will be renamed to id. We should also refer to them as "storage objects" in docs.
// NOTE: a user's handle will now be called "username" (and "nickname" will be non-unique).
// NOTE: user records will now contain device messages which will store device specific details.
// NOTE: all timestamps will use UNIX time (i.e. in seconds).
// NOTE: we'll use a healthcheck on a separate port for GCLB with our GRPC server.
// NOTE: we'll add nk.timemillis() as a helper for millisecond resolution to Lua runtime.
// NOTE: Facebook, (and maybe Google, Game Center, and Steam) will belong on a user not the self message.
// NOTE: self message will now be called account.
// NOTE: add batch friend operations.
// NOTE: all batch operations will be limited to 100 results.
// NOTE: all list operations will return 1 by default and start at 1 up to 100 results.
// NOTE: before/after hook names will not be downcased by default.

option (grpc.gateway.protoc_gen_swagger.options.openapiv2_swagger) = {
  info: {
    title: "Nakama API v2";
@@ -72,6 +45,7 @@ option (grpc.gateway.protoc_gen_swagger.options.openapiv2_swagger) = {
      email: "hello@heroiclabs.com";
    };
  };
  host: "127.0.0.1:7350";
  external_docs: {
    url: "https://heroiclabs.com/docs";
    description: "Nakama server documentation";
@@ -79,6 +53,36 @@ option (grpc.gateway.protoc_gen_swagger.options.openapiv2_swagger) = {
  schemes: HTTP;
  consumes: "application/json";
  produces: "application/json";
  security_definitions: {
    security: {
      key: "BasicAuth";
      value: {
        type: TYPE_BASIC;
      }
    }
    security: {
      // Made up security so we can apply "Bearer <JWT_TOKEN>"
      key: "BearerJwt";
      value: {
        type: TYPE_INVALID;
      }
    }
    security: {
      key: "HttpKeyAuth";
      value: {
        type: TYPE_API_KEY;
        in: IN_HEADER;
        name: "http_key";
      }
    }
  }
  // Default security definition.
  security: {
    security_requirement: {
      key: "BearerJwt";
      value: {};
    }
  }
};

/**
@@ -104,6 +108,14 @@ service Nakama {
      post: "/v2/account/authenticate/custom",
      body: "account"
    };
    option (grpc.gateway.protoc_gen_swagger.options.openapiv2_operation) = {
      security: {
        security_requirement: {
          key: "BasicAuth";
          value: {};
        }
      }
    };
  }

  // Authenticate a user with a device id against the server.
@@ -112,6 +124,14 @@ service Nakama {
      post: "/v2/account/authenticate/device",
      body: "account"
    };
    option (grpc.gateway.protoc_gen_swagger.options.openapiv2_operation) = {
      security: {
        security_requirement: {
          key: "BasicAuth";
          value: {};
        }
      }
    };
  }

  // Authenticate a user with an email+password against the server.
@@ -120,6 +140,14 @@ service Nakama {
      post: "/v2/account/authenticate/email",
      body: "account"
    };
    option (grpc.gateway.protoc_gen_swagger.options.openapiv2_operation) = {
      security: {
        security_requirement: {
          key: "BasicAuth";
          value: {};
        }
      }
    };
  }

  // Authenticate a user with a Facebook OAuth token against the server.
@@ -128,6 +156,14 @@ service Nakama {
      post: "/v2/account/authenticate/facebook",
      body: "account"
    };
    option (grpc.gateway.protoc_gen_swagger.options.openapiv2_operation) = {
      security: {
        security_requirement: {
          key: "BasicAuth";
          value: {};
        }
      }
    };
  }

  // Authenticate a user with Apple's GameCenter against the server.
@@ -136,6 +172,14 @@ service Nakama {
      post: "/v2/account/authenticate/gamecenter",
      body: "account"
    };
    option (grpc.gateway.protoc_gen_swagger.options.openapiv2_operation) = {
      security: {
        security_requirement: {
          key: "BasicAuth";
          value: {};
        }
      }
    };
  }

  // Authenticate a user with Google against the server.
@@ -144,6 +188,14 @@ service Nakama {
      post: "/v2/account/authenticate/google",
      body: "account"
    };
    option (grpc.gateway.protoc_gen_swagger.options.openapiv2_operation) = {
      security: {
        security_requirement: {
          key: "BasicAuth";
          value: {};
        }
      }
    };
  }

  // Authenticate a user with Steam against the server.
@@ -152,6 +204,14 @@ service Nakama {
      post: "/v2/account/authenticate/steam",
      body: "account"
    };
    option (grpc.gateway.protoc_gen_swagger.options.openapiv2_operation) = {
      security: {
        security_requirement: {
          key: "BasicAuth";
          value: {};
        }
      }
    };
  }

  // Block one or more users by ID or username.
@@ -184,7 +244,7 @@ service Nakama {
    option (google.api.http).delete = "/v2/leaderboard/{leaderboard_id}";
  }

  // Delete one or more users by ID or username.
  // Delete one or more notifications for the current user.
  rpc DeleteNotifications (DeleteNotificationsRequest) returns (google.protobuf.Empty) {
    option (google.api.http).delete = "/v2/notification";
  }
@@ -375,6 +435,19 @@ service Nakama {
        get: "/v2/rpc/{id}"
      }
    };
    option (grpc.gateway.protoc_gen_swagger.options.openapiv2_operation) = {
      // Either HTTP key in query param or Bearer authentication.
      security: {
        security_requirement: {
          key: "HttpKeyAuth";
          value: {};
        }
        security_requirement: {
          key: "BearerJwt";
          value: {};
        }
      }
    };
  }

  // Remove the custom ID from the social profiles on the current user's account.
+99 −31
Original line number Diff line number Diff line
@@ -9,6 +9,7 @@
      "email": "hello@heroiclabs.com"
    }
  },
  "host": "127.0.0.1:7350",
  "schemes": [
    "http"
  ],
@@ -102,6 +103,11 @@
        ],
        "tags": [
          "Nakama"
        ],
        "security": [
          {
            "BasicAuth": []
          }
        ]
      }
    },
@@ -129,6 +135,11 @@
        ],
        "tags": [
          "Nakama"
        ],
        "security": [
          {
            "BasicAuth": []
          }
        ]
      }
    },
@@ -156,6 +167,11 @@
        ],
        "tags": [
          "Nakama"
        ],
        "security": [
          {
            "BasicAuth": []
          }
        ]
      }
    },
@@ -183,6 +199,11 @@
        ],
        "tags": [
          "Nakama"
        ],
        "security": [
          {
            "BasicAuth": []
          }
        ]
      }
    },
@@ -210,6 +231,11 @@
        ],
        "tags": [
          "Nakama"
        ],
        "security": [
          {
            "BasicAuth": []
          }
        ]
      }
    },
@@ -237,6 +263,11 @@
        ],
        "tags": [
          "Nakama"
        ],
        "security": [
          {
            "BasicAuth": []
          }
        ]
      }
    },
@@ -264,6 +295,11 @@
        ],
        "tags": [
          "Nakama"
        ],
        "security": [
          {
            "BasicAuth": []
          }
        ]
      }
    },
@@ -720,6 +756,28 @@
            }
          }
        },
        "parameters": [
          {
            "name": "ids",
            "description": "The account id of a user.",
            "in": "query",
            "required": false,
            "type": "array",
            "items": {
              "type": "string"
            }
          },
          {
            "name": "usernames",
            "description": "The account username of a user.",
            "in": "query",
            "required": false,
            "type": "array",
            "items": {
              "type": "string"
            }
          }
        ],
        "tags": [
          "Nakama"
        ]
@@ -1292,7 +1350,7 @@
        ]
      },
      "delete": {
        "summary": "Delete one or more users by ID or username.",
        "summary": "Delete one or more notifications for the current user.",
        "operationId": "DeleteNotifications",
        "responses": {
          "200": {
@@ -1302,6 +1360,18 @@
            }
          }
        },
        "parameters": [
          {
            "name": "ids",
            "description": "The id of notifications.",
            "in": "query",
            "required": false,
            "type": "array",
            "items": {
              "type": "string"
            }
          }
        ],
        "tags": [
          "Nakama"
        ]
@@ -1343,6 +1413,12 @@
        ],
        "tags": [
          "Nakama"
        ],
        "security": [
          {
            "BearerJwt": [],
            "HttpKeyAuth": []
          }
        ]
      },
      "post": {
@@ -1374,6 +1450,12 @@
        ],
        "tags": [
          "Nakama"
        ],
        "security": [
          {
            "BearerJwt": [],
            "HttpKeyAuth": []
          }
        ]
      }
    },
@@ -2678,44 +2760,30 @@
      },
      "description": "Write objects to the storage engine."
    },
    "protobufBoolValue": {
      "type": "object",
      "properties": {
        "value": {
          "type": "boolean",
          "format": "boolean",
          "description": "The bool value."
        }
      },
      "description": "Wrapper message for `bool`.\n\nThe JSON representation for `BoolValue` is JSON `true` and `false`."
    },
    "protobufEmpty": {
      "type": "object",
      "description": "service Foo {\n      rpc Bar(google.protobuf.Empty) returns (google.protobuf.Empty);\n    }\n\nThe JSON representation for `Empty` is empty JSON object `{}`.",
      "title": "A generic empty message that you can re-use to avoid defining duplicated\nempty messages in your APIs. A typical example is to use it as the request\nor the response type of an API method. For instance:"
    },
    "protobufInt32Value": {
      "type": "object",
      "properties": {
        "value": {
          "type": "integer",
          "format": "int32",
          "description": "The int32 value."
    }
  },
      "description": "Wrapper message for `int32`.\n\nThe JSON representation for `Int32Value` is JSON number."
  "securityDefinitions": {
    "BasicAuth": {
      "type": "basic"
    },
    "protobufStringValue": {
      "type": "object",
      "properties": {
        "value": {
          "type": "string",
          "description": "The string value."
        }
    "BearerJwt": {
      "type": ""
    },
      "description": "Wrapper message for `string`.\n\nThe JSON representation for `StringValue` is JSON string."
    "HttpKeyAuth": {
      "type": "apiKey",
      "name": "http_key",
      "in": "header"
    }
  },
  "security": [
    {
      "BearerJwt": []
    }
  ],
  "externalDocs": {
    "description": "Nakama server documentation",
    "url": "https://heroiclabs.com/docs"
Loading