implemented getting user from signature
This commit is contained in:
		
							
								
								
									
										39
									
								
								internal/rest_handler/test_auth.go
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										39
									
								
								internal/rest_handler/test_auth.go
									
									
									
									
									
										Normal file
									
								
							| @@ -0,0 +1,39 @@ | ||||
| package rest_handler | ||||
|  | ||||
| import ( | ||||
| 	"fmt" | ||||
| 	"io" | ||||
| 	"net/http" | ||||
|  | ||||
| 	"gitea.elara.ws/Hazel/hangman/internal/game" | ||||
| 	"github.com/labstack/echo/v4" | ||||
| ) | ||||
|  | ||||
| func TestAuth(c echo.Context) error { | ||||
| 	session := game.GetSession(c.Param("session")) | ||||
|  | ||||
| 	type TestResults struct { | ||||
| 		SignatureValid bool | ||||
| 		User           *string | ||||
| 	} | ||||
|  | ||||
| 	sig := c.Request().Header.Get("signature") | ||||
| 	body, _ := io.ReadAll(c.Request().Body) | ||||
| 	fmt.Println(sig) | ||||
|  | ||||
| 	u := session.VerifySignature(sig, body) | ||||
| 	var resp TestResults | ||||
| 	if u == nil { | ||||
| 		resp = TestResults{ | ||||
| 			SignatureValid: false, | ||||
| 			User:           nil, | ||||
| 		} | ||||
| 	} else { | ||||
| 		resp = TestResults{ | ||||
| 			SignatureValid: true, | ||||
| 			User:           &u.Name, | ||||
| 		} | ||||
| 	} | ||||
|  | ||||
| 	return c.JSON(http.StatusOK, resp) | ||||
| } | ||||
		Reference in New Issue
	
	Block a user