Commit 68b2fde6 authored by Andrei Mihu's avatar Andrei Mihu
Browse files

Refresh tokens feature. (#527)

parent eda7a407
Loading
Loading
Loading
Loading
+1 −0
Original line number Diff line number Diff line
@@ -9,6 +9,7 @@ This is a major release of the server but fully backwards compatible with the 2.

### Added
- New JavaScript runtime to write server code.
- Introduce refresh tokens that can be used to refresh sessions.
- New Realtime Parties for users to create teamplay in games. Users can form a party and communicate with party members.
- Add party matching support to the Matchmaker.
- Add options to the Matchmaker to control how long tickets wait for their preferred match.
+696 −685

File changed.

Preview size limit exceeded, changes collapsed.

+81 −0
Original line number Diff line number Diff line
@@ -139,6 +139,40 @@ func local_request_Nakama_AddGroupUsers_0(ctx context.Context, marshaler runtime

}

func request_Nakama_SessionRefresh_0(ctx context.Context, marshaler runtime.Marshaler, client NakamaClient, req *http.Request, pathParams map[string]string) (proto.Message, runtime.ServerMetadata, error) {
	var protoReq api.SessionRefreshRequest
	var metadata runtime.ServerMetadata

	newReader, berr := utilities.IOReaderFactory(req.Body)
	if berr != nil {
		return nil, metadata, status.Errorf(codes.InvalidArgument, "%v", berr)
	}
	if err := marshaler.NewDecoder(newReader()).Decode(&protoReq); err != nil && err != io.EOF {
		return nil, metadata, status.Errorf(codes.InvalidArgument, "%v", err)
	}

	msg, err := client.SessionRefresh(ctx, &protoReq, grpc.Header(&metadata.HeaderMD), grpc.Trailer(&metadata.TrailerMD))
	return msg, metadata, err

}

func local_request_Nakama_SessionRefresh_0(ctx context.Context, marshaler runtime.Marshaler, server NakamaServer, req *http.Request, pathParams map[string]string) (proto.Message, runtime.ServerMetadata, error) {
	var protoReq api.SessionRefreshRequest
	var metadata runtime.ServerMetadata

	newReader, berr := utilities.IOReaderFactory(req.Body)
	if berr != nil {
		return nil, metadata, status.Errorf(codes.InvalidArgument, "%v", berr)
	}
	if err := marshaler.NewDecoder(newReader()).Decode(&protoReq); err != nil && err != io.EOF {
		return nil, metadata, status.Errorf(codes.InvalidArgument, "%v", err)
	}

	msg, err := server.SessionRefresh(ctx, &protoReq)
	return msg, metadata, err

}

var (
	filter_Nakama_AuthenticateApple_0 = &utilities.DoubleArray{Encoding: map[string]int{"account": 0}, Base: []int{1, 1, 0}, Check: []int{0, 1, 2}}
)
@@ -3495,6 +3529,29 @@ func RegisterNakamaHandlerServer(ctx context.Context, mux *runtime.ServeMux, ser

	})

	mux.Handle("POST", pattern_Nakama_SessionRefresh_0, func(w http.ResponseWriter, req *http.Request, pathParams map[string]string) {
		ctx, cancel := context.WithCancel(req.Context())
		defer cancel()
		var stream runtime.ServerTransportStream
		ctx = grpc.NewContextWithServerTransportStream(ctx, &stream)
		inboundMarshaler, outboundMarshaler := runtime.MarshalerForRequest(mux, req)
		rctx, err := runtime.AnnotateIncomingContext(ctx, mux, req, "/nakama.api.Nakama/SessionRefresh")
		if err != nil {
			runtime.HTTPError(ctx, mux, outboundMarshaler, w, req, err)
			return
		}
		resp, md, err := local_request_Nakama_SessionRefresh_0(rctx, inboundMarshaler, server, req, pathParams)
		md.HeaderMD, md.TrailerMD = metadata.Join(md.HeaderMD, stream.Header()), metadata.Join(md.TrailerMD, stream.Trailer())
		ctx = runtime.NewServerMetadataContext(ctx, md)
		if err != nil {
			runtime.HTTPError(ctx, mux, outboundMarshaler, w, req, err)
			return
		}

		forward_Nakama_SessionRefresh_0(ctx, mux, outboundMarshaler, w, req, resp, mux.GetForwardResponseOptions()...)

	})

	mux.Handle("POST", pattern_Nakama_AuthenticateApple_0, func(w http.ResponseWriter, req *http.Request, pathParams map[string]string) {
		ctx, cancel := context.WithCancel(req.Context())
		defer cancel()
@@ -5140,6 +5197,26 @@ func RegisterNakamaHandlerClient(ctx context.Context, mux *runtime.ServeMux, cli

	})

	mux.Handle("POST", pattern_Nakama_SessionRefresh_0, func(w http.ResponseWriter, req *http.Request, pathParams map[string]string) {
		ctx, cancel := context.WithCancel(req.Context())
		defer cancel()
		inboundMarshaler, outboundMarshaler := runtime.MarshalerForRequest(mux, req)
		rctx, err := runtime.AnnotateContext(ctx, mux, req, "/nakama.api.Nakama/SessionRefresh")
		if err != nil {
			runtime.HTTPError(ctx, mux, outboundMarshaler, w, req, err)
			return
		}
		resp, md, err := request_Nakama_SessionRefresh_0(rctx, inboundMarshaler, client, req, pathParams)
		ctx = runtime.NewServerMetadataContext(ctx, md)
		if err != nil {
			runtime.HTTPError(ctx, mux, outboundMarshaler, w, req, err)
			return
		}

		forward_Nakama_SessionRefresh_0(ctx, mux, outboundMarshaler, w, req, resp, mux.GetForwardResponseOptions()...)

	})

	mux.Handle("POST", pattern_Nakama_AuthenticateApple_0, func(w http.ResponseWriter, req *http.Request, pathParams map[string]string) {
		ctx, cancel := context.WithCancel(req.Context())
		defer cancel()
@@ -6508,6 +6585,8 @@ var (

	pattern_Nakama_AddGroupUsers_0 = runtime.MustPattern(runtime.NewPattern(1, []int{2, 0, 2, 1, 1, 0, 4, 1, 5, 2, 2, 3}, []string{"v2", "group", "group_id", "add"}, ""))

	pattern_Nakama_SessionRefresh_0 = runtime.MustPattern(runtime.NewPattern(1, []int{2, 0, 2, 1, 2, 2, 2, 3}, []string{"v2", "account", "session", "refresh"}, ""))

	pattern_Nakama_AuthenticateApple_0 = runtime.MustPattern(runtime.NewPattern(1, []int{2, 0, 2, 1, 2, 2, 2, 3}, []string{"v2", "account", "authenticate", "apple"}, ""))

	pattern_Nakama_AuthenticateCustom_0 = runtime.MustPattern(runtime.NewPattern(1, []int{2, 0, 2, 1, 2, 2, 2, 3}, []string{"v2", "account", "authenticate", "custom"}, ""))
@@ -6650,6 +6729,8 @@ var (

	forward_Nakama_AddGroupUsers_0 = runtime.ForwardResponseMessage

	forward_Nakama_SessionRefresh_0 = runtime.ForwardResponseMessage

	forward_Nakama_AuthenticateApple_0 = runtime.ForwardResponseMessage

	forward_Nakama_AuthenticateCustom_0 = runtime.ForwardResponseMessage
+16 −0
Original line number Diff line number Diff line
@@ -96,6 +96,22 @@ service Nakama {
    option (google.api.http).post = "/v2/group/{group_id}/add";
  }

  // Refresh a user's session using a refresh token retrieved from a previous authentication request.
  rpc SessionRefresh (api.SessionRefreshRequest) returns (api.Session) {
    option (google.api.http) = {
      post: "/v2/account/session/refresh",
      body: "*"
    };
    option (grpc.gateway.protoc_gen_openapiv2.options.openapiv2_operation) = {
      security: {
        security_requirement: {
          key: "BasicAuth";
          value: {};
        }
      }
    };
  }

  // Authenticate a user with an Apple ID against the server.
  rpc AuthenticateApple (api.AuthenticateAppleRequest) returns (api.Session) {
    option (google.api.http) = {
+59 −0
Original line number Diff line number Diff line
@@ -886,6 +886,44 @@
        ]
      }
    },
    "/v2/account/session/refresh": {
      "post": {
        "summary": "Refresh a user's session using a refresh token retrieved from a previous authentication request.",
        "operationId": "Nakama_SessionRefresh",
        "responses": {
          "200": {
            "description": "A successful response.",
            "schema": {
              "$ref": "#/definitions/apiSession"
            }
          },
          "default": {
            "description": "An unexpected error response.",
            "schema": {
              "$ref": "#/definitions/rpcStatus"
            }
          }
        },
        "parameters": [
          {
            "name": "body",
            "in": "body",
            "required": true,
            "schema": {
              "$ref": "#/definitions/apiSessionRefreshRequest"
            }
          }
        ],
        "tags": [
          "Nakama"
        ],
        "security": [
          {
            "BasicAuth": []
          }
        ]
      }
    },
    "/v2/account/unlink/apple": {
      "post": {
        "summary": "Remove the Apple ID from the social profiles on the current user's account.",
@@ -3734,10 +3772,31 @@
        "token": {
          "type": "string",
          "description": "Authentication credentials."
        },
        "refreshToken": {
          "type": "string",
          "description": "Refresh token that can be used for session token renewal."
        }
      },
      "description": "A user's session used to authenticate messages."
    },
    "apiSessionRefreshRequest": {
      "type": "object",
      "properties": {
        "token": {
          "type": "string",
          "description": "Refresh token."
        },
        "vars": {
          "type": "object",
          "additionalProperties": {
            "type": "string"
          },
          "description": "Extra information that will be bundled in the session token."
        }
      },
      "description": "Authenticate against the server with a refresh token."
    },
    "apiStorageObject": {
      "type": "object",
      "properties": {
Loading