Skip to content

Commit

Permalink
deps (#29)
Browse files Browse the repository at this point in the history
  • Loading branch information
swuecho authored Jun 30, 2024
1 parent bd1c68a commit 3766e71
Show file tree
Hide file tree
Showing 4 changed files with 18 additions and 38 deletions.
29 changes: 5 additions & 24 deletions api/Note.fs
Original file line number Diff line number Diff line change
Expand Up @@ -129,17 +129,8 @@ let createNewUser conn email password =

//let jwtSecret = JwtSecrets.GetJwtSecret conn "logbook"

// Get the JWT key from the environment variable
let jwtKey =
match System.Environment.GetEnvironmentVariable("JWT_SECRET") with
| null -> failwith "JWT_SECRET environment variable not found"
| key -> key

// Get the audience from the environment variable
let audience =
match System.Environment.GetEnvironmentVariable("JWT_AUDIENCE") with
| null -> failwith "JWT_AUDIENCE environment variable not found"
| aud -> aud
let jwtKey = Util.getEnvVar "JWT_SECRET"
let audience = Util.getEnvVar "JWT_AUDIENCE"


let issuer = "logbook-swuecho.github.com"
Expand All @@ -149,6 +140,7 @@ let createNewUser conn email password =

jwt


let login: HttpHandler =
fun ctx ->
Request.mapJson
Expand All @@ -165,19 +157,8 @@ let login: HttpHandler =
// check if user is admin
let role = if user.IsSuperuser then "admin" else "user"

// let jwtSecret = JwtSecrets.GetJwtSecret conn "logbook"

let jwtKey =
match System.Environment.GetEnvironmentVariable("JWT_SECRET") with
| null -> failwith "JWT_SECRET environment variable not found"
| key -> key

// Get the audience from the environment variable
let audience =
match System.Environment.GetEnvironmentVariable("JWT_AUDIENCE") with
| null -> failwith "JWT_AUDIENCE environment variable not found"
| aud -> aud

let jwtKey = Util.getEnvVar "JWT_SECRET"
let audience = Util.getEnvVar "JWT_AUDIENCE"
let issuer = "logbook-swuecho.github.com"

if passwordMatches then
Expand Down
5 changes: 3 additions & 2 deletions api/Notepad.fsproj
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
<TargetFramework>net7.0</TargetFramework>
</PropertyGroup>
<ItemGroup>
<Compile Include="Util.fs" />
<Compile Include="Auth.fs" />
<Compile Include="HttpAuth.fs" />
<Compile Include="Token.fs" />
Expand All @@ -23,8 +24,8 @@
<PackageReference Include="FSharp.Data" Version="6.2.0" />
<PackageReference Include="jieba.NET" Version="0.42.2" />
<PackageReference Include="Microsoft.AspNetCore.Authentication.JwtBearer" Version="7.0.5" />
<PackageReference Include="Npgsql" Version="7.0.4" />
<PackageReference Include="Npgsql" Version="8.0.3" />
<PackageReference Include="Npgsql.FSharp" Version="5.7.0" />
<PackageReference Include="System.IdentityModel.Tokens.Jwt" Version="6.30.1" />
<PackageReference Include="System.IdentityModel.Tokens.Jwt" Version="7.6.0" />
</ItemGroup>
</Project>
16 changes: 4 additions & 12 deletions api/Program.fs
Original file line number Diff line number Diff line change
Expand Up @@ -55,19 +55,11 @@ let authUserMiddleware (app: IApplicationBuilder) =
app.Use(middleware)




let authService (services: IServiceCollection) =

// Get the JWT key from the environment variable
let jwtKey =
match System.Environment.GetEnvironmentVariable("JWT_SECRET") with
| null -> failwith "JWT_SECRET environment variable not found"
| key -> key

// Get the audience from the environment variable
let audience =
match System.Environment.GetEnvironmentVariable("JWT_AUDIENCE") with
| null -> failwith "JWT_AUDIENCE environment variable not found"
| aud -> aud
let jwtKey = Util.getEnvVar "JWT_SECRET"
let audience = Util.getEnvVar "JWT_AUDIENCE"


let _ =
Expand Down
6 changes: 6 additions & 0 deletions api/Util.fs
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
module Util

let getEnvVar varName =
match System.Environment.GetEnvironmentVariable(varName) with
| null -> failwith (sprintf "%s environment variable not found" varName)
| value -> value

0 comments on commit 3766e71

Please sign in to comment.