From 32637e5c37dd6a500f8cfd9ba3d4074fb5cf5073 Mon Sep 17 00:00:00 2001 From: nxshock Date: Sat, 20 Jul 2019 11:30:16 +0500 Subject: [PATCH] Update login method structures and comments --- internal/handlers.go | 4 ++-- internal/models/login/reply.go | 35 +++++++++++++++++++++++++++++----- 2 files changed, 32 insertions(+), 7 deletions(-) diff --git a/internal/handlers.go b/internal/handlers.go index 71d8e78..d152190 100644 --- a/internal/handlers.go +++ b/internal/handlers.go @@ -37,7 +37,7 @@ func LoginHandler(w http.ResponseWriter, r *http.Request) { // https://models.org/docs/spec/client_server/latest#get-models-client-r0-login case "GET": { - response := login.GetLoginReply{ + response := login.GetReply{ Flows: []login.Flow{ login.Flow{Type: common.AuthenticationTypePassword}, }, @@ -62,7 +62,7 @@ func LoginHandler(w http.ResponseWriter, r *http.Request) { return } - response := login.LoginReply{ + response := login.PostReply{ UserID: request.Identifier.User, AccessToken: token, } diff --git a/internal/models/login/reply.go b/internal/models/login/reply.go index 4098df9..87d655d 100644 --- a/internal/models/login/reply.go +++ b/internal/models/login/reply.go @@ -4,17 +4,42 @@ import ( common "github.com/nxshock/signaller/internal/models/common" ) -type LoginReply struct { - AccessToken string `json:"access_token"` - HomeServer string `json:"home_server,omitempty"` // TODO: check api - UserID string `json:"user_id"` +// PostReply is returned reply from POST login method +// https://matrix.org/docs/spec/client_server/latest#get-matrix-client-r0-login +type PostReply struct { + UserID string `json:"user_id"` // The fully-qualified Matrix ID that has been registered. + AccessToken string `json:"access_token"` // An access token for the account. This access token can then be used to authorize other requests. + DeviceID string `json:"device_id"` // ID of the logged-in device. Will be the same as the corresponding parameter in the request, if one was specified. + WellKnown DiscoveryInformation `json:"well_known,omitempty"` // Optional client configuration provided by the server. If present, clients SHOULD use the provided object to reconfigure themselves, optionally validating the URLs within. This object takes the same form as the one returned from .well-known autodiscovery. } +// DiscoveryInformation is client configuration provided by the server +// https://matrix.org/docs/spec/client_server/latest#get-matrix-client-r0-login +type DiscoveryInformation struct { + HomeServer HomeserverInformation `json:"m.homeserver"` // Required. Used by clients to discover homeserver information. + IdentityServer IdentityServerInformation `json:"m.identity_server,omitempty"` // Used by clients to discover ide +} + +// HomeserverInformation is used by clients to discover homeserver information +// https://matrix.org/docs/spec/client_server/latest#get-matrix-client-r0-login +type HomeserverInformation struct { + BaseURL string `json:"base_url"` // Required. The base URL for the homeserver for client-server connections. +} + +// IdentityServerInformation is used by clients to discover identity server information. +// https://matrix.org/docs/spec/client_server/latest#get-matrix-client-r0-login +type IdentityServerInformation struct { + BaseURL string `json:"base_url"` // Required. The base URL for the homeserver for client-server connections. +} + +// Flow is the homeserver's supported login types +// https://matrix.org/docs/spec/client_server/latest#get-matrix-client-r0-login type Flow struct { Type common.AuthenticationType `json:"type"` } +// GetReply is returned reply from GET login method // https://matrix.org/docs/spec/client_server/latest#get-matrix-client-r0-login -type GetLoginReply struct { +type GetReply struct { Flows []Flow `json:"flows"` // The homeserver's supported login types }