scala-pocketbase-oauth-attempt/src/main/scala/example/pocketbase/Models.scala

79 lines
2.0 KiB
Scala

package example.pocketbase
import upickle.default._
object Models {
final case class AuthProviderInfo(
name: String,
state: String,
codeVerifier: String,
codeChallenge: String,
codeChallengeMethod: String,
authUrl: String
) derives ReadWriter
final case class AvailableAuthMethods(
usernamePassword: Boolean,
emailPassword: Boolean,
authProviders: List[AuthProviderInfo]
) derives ReadWriter
// auth methods
/*
{
"usernamePassword": false,
"emailPassword": true,
"authProviders": [
{
"name": "github",
"state": "3Yd8jNkK_6PJG6hPWwBjLqKwse6Ejd",
"codeVerifier": "KxFDWz1B3fxscCDJ_9gHQhLuh__ie7",
"codeChallenge": "NM1oVexB6Q6QH8uPtOUfK7tq4pmu4Jz6lNDIwoxHZNE=",
"codeChallengeMethod": "S256",
"authUrl": "https://github.com/login/oauth/authorize?client_id=demo&code_challenge=NM1oVexB6Q6QH8uPtOUfK7tq4pmu4Jz6lNDIwoxHZNE%3D&code_challenge_method=S256&response_type=code&scope=user&state=3Yd8jNkK_6PJG6hPWwBjLqKwse6Ejd&redirect_uri="
}
]
}
*
*/
final case class BaseAccountData(
id: String,
collectionId: String,
collectionName: String,
created: String,
updated: String,
username: String,
email: String,
verified: Boolean,
emailVisibility: Boolean
) derives ReadWriter
final case class AuthReply(
token: String,
record: BaseAccountData
) derives ReadWriter
// auth reply
/*
*
*{
"token": "eyJhbGciOiJIUzI1NiJ9.eyJpZCI6IjRxMXhsY2xtZmxva3UzMyIsInR5cGUiOiJhdXRoUmVjb3JkIiwiY29sbGVjdGlvbklkIjoiX3BiX3VzZXJzX2F1dGhfIiwiZXhwIjoyMjA4OTg1MjYxfQ.UwD8JvkbQtXpymT09d7J6fdA0aP9g4FJ1GPh_ggEkzc",
"record": {
"id": "8171022dc95a4ed",
"collectionId": "d2972397d45614e",
"collectionName": "users",
"created": "2022-06-24 06:24:18.434Z",
"updated": "2022-06-24 06:24:18.889Z",
"username": "test@example.com",
"email": "test@example.com",
"verified": true,
"emailVisibility": false,
"someCustomField": "example 123"
}
}
* */
}