Skip to content

Commit

Permalink
Start work in a auth lib to be used in the api scaffold
Browse files Browse the repository at this point in the history
  • Loading branch information
FernandoAvanzo committed Oct 20, 2024
1 parent 41ce6f2 commit 05775ab
Show file tree
Hide file tree
Showing 6 changed files with 86 additions and 1 deletion.
16 changes: 16 additions & 0 deletions authenticator/Readme.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
### Authenticator Tool

Tool to handle API authentication flows, including JWT token generation, validation, and management.

### Roadmap

- [ ] Create a Notion space to manage this project
- [ ] Finish building the AI scaffold suggestion
- [ ] Discover how to publish the library
- [ ] Discover how to use a local version of the library
- [ ] Add the library to the API project
- [ ] Implement an authentication flow in the API using the Auth library


### References
- [My Notion JSON Web Tokens](https://www.notion.so/fernando-avanzo/Doc-JSON-Web-Tokens-125b3def3e7c80099293f2b8ec520b9b?pvs=4)
25 changes: 25 additions & 0 deletions authenticator/build.gradle.kts
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
plugins {
kotlin("jvm") version "2.0.21"
`maven-publish`
}

group = "avanzo.ktor.auth"
version = "1.0.0"

repositories {
mavenCentral()
}

dependencies {
implementation("io.ktor:ktor-server-auth:2.3.0")
implementation("io.ktor:ktor-server-auth-jwt:2.3.0")
testImplementation(kotlin("test"))
}

publishing {
publications {
create<MavenPublication>("mavenJava") {
from(components["java"])
}
}
}
14 changes: 14 additions & 0 deletions authenticator/src/main/kotlin/avanzo/ktor/auth/JwtConfig.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
package avanzo.ktor.auth

import com.auth0.jwt.algorithms.Algorithm


data class JwtConfig(
val realm: String,
val issuer: String,
val secret: String,
val audience: String,
val expiration: Long // in milliseconds
) {
val algorithm: Algorithm = Algorithm.HMAC256(secret)
}
4 changes: 3 additions & 1 deletion settings.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -4,4 +4,6 @@ plugins {
}

rootProject.name = "ktor-api-scaffold"
include("api")
include("api")
include("authenticator")
include("utils")
1 change: 1 addition & 0 deletions utils/Readme.md
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
# Scripts to help with boring tasks
27 changes: 27 additions & 0 deletions utils/build-kotlin-folder-structure.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
#!/bin/bash
set -euo pipefail

declare -r ROOT="$HOME/Projects/ktor-api-scaffold"
declare module=${1-"invalid path"}


if [ "$module" != "invalid path" ]; then
# Rest of your commands go here
declare -r module="$ROOT/$module"

if [ -d "$module" ]; then
# Run your remaining commands here
mkdir -p "$module/src/main/kotlin"
mkdir -p "$module/src/main/resources"
mkdir -p "$module/src/test/kotlin"
mkdir -p "$module/src/test/resources"

else
echo "Error: The provided path '$module' is not a valid folder."
exit 1
fi

else
echo "Path invalid"
exit 1
fi

0 comments on commit 05775ab

Please sign in to comment.