Skip to content

Commit

Permalink
guid as user id
Browse files Browse the repository at this point in the history
  • Loading branch information
brase committed Mar 13, 2020
1 parent 00b0c43 commit 868c773
Show file tree
Hide file tree
Showing 4 changed files with 8 additions and 11 deletions.
9 changes: 3 additions & 6 deletions src/Server/Authentication.fs
Original file line number Diff line number Diff line change
Expand Up @@ -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))
Expand Down
2 changes: 1 addition & 1 deletion src/Server/Events.fs
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ and PasswordChanged = {
Id: UserId
Password: string
}
and UserId = | UserId of System.Guid
and UserId = System.Guid


type Error =
Expand Down
6 changes: 3 additions & 3 deletions src/Server/Smapi.fs
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
Expand All @@ -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
Expand Down
2 changes: 1 addition & 1 deletion src/Server/UserCompositions.fs
Original file line number Diff line number Diff line change
Expand Up @@ -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 }
Expand Down

0 comments on commit 868c773

Please sign in to comment.