-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
11 changed files
with
100 additions
and
13 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,3 @@ | ||
# Hypermode Simple Example Plugin | ||
|
||
This is a _very_ simple example showing how to write a Hypermode plugin. | ||
It doesn't do very much, but it should illustrate how to write a function. | ||
|
||
See [./assembly/index.ts](./assembly/index.ts) for the implementation. | ||
This is an example showing how to write a Hypermode plugin that uses auth. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
@echo off | ||
|
||
:: This build script works best for examples that are in this repository. | ||
:: If you are using this as a template for your own project, you may need to modify this script, | ||
:: to invoke the modus-go-build tool with the correct path to your project. | ||
|
||
SET "PROJECTDIR=%~dp0" | ||
pushd ..\..\tools\modus-go-build > nul | ||
go run . "%PROJECTDIR%" | ||
set "exit_code=%ERRORLEVEL%" | ||
popd > nul | ||
exit /b %exit_code% |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
#!/bin/bash | ||
|
||
# This build script works best for examples that are in this repository. | ||
# If you are using this as a template for your own project, you may need to modify this script, | ||
# to invoke the modus-go-build tool with the correct path to your project. | ||
|
||
PROJECTDIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" >/dev/null 2>&1 && pwd )" | ||
pushd ../../tools/modus-go-build > /dev/null | ||
go run . "$PROJECTDIR" | ||
exit_code=$? | ||
popd > /dev/null | ||
exit $exit_code |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
module auth-example | ||
|
||
go 1.23.0 | ||
|
||
require github.com/hypermodeinc/modus/sdk/go v0.0.0 | ||
|
||
replace github.com/hypermodeinc/modus/sdk/go => ../../ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
{ | ||
"$schema": "https://manifest.hypermode.com/hypermode.json", | ||
"models": { | ||
// No models are used by this example, but if you add any, they would go here. | ||
}, | ||
"hosts": { | ||
// No hosts are used by this example, but if you add any, they would go here. | ||
}, | ||
"collections": { | ||
// No collections are used by this example, but if you add any, they would go here. | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
/* | ||
* This example is part of the Modus project, licensed under the Apache License 2.0. | ||
* You may modify and use this example in accordance with the license. | ||
* See the LICENSE file that accompanied this code for further details. | ||
*/ | ||
|
||
package main | ||
|
||
import ( | ||
"github.com/hypermodeinc/modus/sdk/go/pkg/auth" | ||
) | ||
|
||
type Claims struct { | ||
Exp int64 `json:"exp"` | ||
Iat int64 `json:"iat"` | ||
Iss string `json:"iss"` | ||
Jti string `json:"jti"` | ||
Nbf int64 `json:"nbf"` | ||
Sub string `json:"sub"` | ||
UserId string `json:"user-id"` | ||
} | ||
|
||
func GetJWTClaims() (*Claims, error) { | ||
return auth.GetJWTClaims[*Claims]() | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
package auth | ||
|
||
import ( | ||
"errors" | ||
"os" | ||
|
||
"github.com/hypermodeinc/modus/sdk/go/pkg/utils" | ||
) | ||
|
||
type JWT struct{} | ||
|
||
func GetJWTClaims[T any]() (T, error) { | ||
var claims T | ||
claimsStr := os.Getenv("JWT_CLAIMS") | ||
if claimsStr == "" { | ||
return claims, errors.New("JWT claims not found") | ||
} | ||
err := utils.JsonDeserialize([]byte(claimsStr), &claims) // Convert claimsStr to byte slice | ||
if err != nil { | ||
return claims, err | ||
} | ||
|
||
return claims, nil | ||
} |