From 868c7732e52b4d9858852abfc68a50978741ceb9 Mon Sep 17 00:00:00 2001 From: brase Date: Fri, 13 Mar 2020 21:23:11 +0100 Subject: [PATCH] guid as user id --- src/Server/Authentication.fs | 9 +++------ src/Server/Events.fs | 2 +- src/Server/Smapi.fs | 6 +++--- src/Server/UserCompositions.fs | 2 +- 4 files changed, 8 insertions(+), 11 deletions(-) diff --git a/src/Server/Authentication.fs b/src/Server/Authentication.fs index 5e1c145..16c627d 100644 --- a/src/Server/Authentication.fs +++ b/src/Server/Authentication.fs @@ -59,21 +59,18 @@ let claimsToAuthUser (cp:ClaimsPrincipal):AuthenticatedUser = cp.Claims |> Seq.fold (fun state c -> match c.Type with | JwtRegisteredClaimNames.Sub -> { state with Email = c.Value} - | ClaimTypes.Sid -> { state with Id = UserId (Guid.Parse(c.Value))} + | ClaimTypes.Sid -> { state with Id = Guid.Parse(c.Value)} | ClaimTypes.Role -> { state with Roles = (state.Roles @ [c.Value])} | _ -> state) - { Id = UserId(Guid.Empty) + { Id = Guid.Empty Email = "" Roles = [] } let generateToken secret issuer (user:User) = - let guid (UserId id) = - id - let claims = [| Claim(JwtRegisteredClaimNames.Sub, user.Email) Claim(JwtRegisteredClaimNames.Jti, Guid.NewGuid().ToString()) - Claim(ClaimTypes.Sid, (guid user.Id).ToString()) + Claim(ClaimTypes.Sid, (user.Id).ToString()) Claim(ClaimTypes.Role, "Admin") |] //TODO: Not everone is admin; use literal let roles = user.Roles |> List.map (fun r -> Claim(ClaimTypes.Role, r)) diff --git a/src/Server/Events.fs b/src/Server/Events.fs index 087ebd2..1fc3047 100644 --- a/src/Server/Events.fs +++ b/src/Server/Events.fs @@ -74,7 +74,7 @@ and PasswordChanged = { Id: UserId Password: string } -and UserId = | UserId of System.Guid +and UserId = System.Guid type Error = diff --git a/src/Server/Smapi.fs b/src/Server/Smapi.fs index 8f46f86..5b67ed1 100644 --- a/src/Server/Smapi.fs +++ b/src/Server/Smapi.fs @@ -184,7 +184,7 @@ module Smapi = | true -> None | false -> Some (List.reduce (fun _ i -> i) filteredLs) - let processGetMediaURI eventstore s (UserId u) = + let processGetMediaURI eventstore s userId = let req = GetMediaURIRequest.Parse s let id = req.Body.GetMediaUri.Id let episode = match id with @@ -203,7 +203,7 @@ module Smapi = | Some (PlayEpisodeStopped data) -> if data.Id = episodeId then Some (data.Position) else None | _ -> None - let (events, _) = getAllEventsFromStreamById eventstore (getPlayEpisodeStreamId u episode.FeedId episode.Id) + let (events, _) = getAllEventsFromStreamById eventstore (getPlayEpisodeStreamId userId episode.FeedId episode.Id) let position = match lastPlayEpisodeStopped events with | IsNeededPlaySecondsReported episode.Id position -> Some position | IsNeededPlayEpisodeStopped episode.Id position -> Some position @@ -219,7 +219,7 @@ module Smapi = PollIntervall = 500 } ok (toLastUpdateXml result) - let processReportPlaySecondsRequest eventstore s (UserId u) = + let processReportPlaySecondsRequest eventstore s u = let req = ReportPlaySecondsRequest.Parse s let id = req.Body.ReportPlaySeconds.Id let position = req.Body.ReportPlaySeconds.OffsetMillis diff --git a/src/Server/UserCompositions.fs b/src/Server/UserCompositions.fs index 5bc98f5..8fe90e4 100644 --- a/src/Server/UserCompositions.fs +++ b/src/Server/UserCompositions.fs @@ -33,7 +33,7 @@ let getUserComposition eventStore email = let addUserComposition eventStore (rendition:AddUserRendition) = let salt = generateSalt() let hash = calculateHash rendition.Password salt - UserAdded { Id = Guid.NewGuid() |> UserId + UserAdded { Id = Guid.NewGuid() Email = rendition.EMail PasswordHash = hash Salt = salt }