mirror of
https://github.com/steveiliop56/tinyauth.git
synced 2026-03-03 13:22:01 +00:00
Compare commits
3 Commits
feat/useri
...
refactor/u
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
01581fc359 | ||
|
|
914e46f565 | ||
|
|
570da3590d |
Binary file not shown.
|
Before Width: | Height: | Size: 3.6 MiB After Width: | Height: | Size: 4.5 MiB |
@@ -37,7 +37,7 @@
|
|||||||
"devDependencies": {
|
"devDependencies": {
|
||||||
"@eslint/js": "^10.0.1",
|
"@eslint/js": "^10.0.1",
|
||||||
"@tanstack/eslint-plugin-query": "^5.91.4",
|
"@tanstack/eslint-plugin-query": "^5.91.4",
|
||||||
"@types/node": "^25.3.2",
|
"@types/node": "^25.3.1",
|
||||||
"@types/react": "^19.2.14",
|
"@types/react": "^19.2.14",
|
||||||
"@types/react-dom": "^19.2.3",
|
"@types/react-dom": "^19.2.3",
|
||||||
"@vitejs/plugin-react": "^5.1.4",
|
"@vitejs/plugin-react": "^5.1.4",
|
||||||
@@ -417,7 +417,7 @@
|
|||||||
|
|
||||||
"@types/ms": ["@types/ms@2.1.0", "", {}, "sha512-GsCCIZDE/p3i96vtEqx+7dBUGXrc7zeSK3wwPHIaRThS+9OhWIXRqzs4d6k1SVU8g91DrNRWxWUGhp5KXQb2VA=="],
|
"@types/ms": ["@types/ms@2.1.0", "", {}, "sha512-GsCCIZDE/p3i96vtEqx+7dBUGXrc7zeSK3wwPHIaRThS+9OhWIXRqzs4d6k1SVU8g91DrNRWxWUGhp5KXQb2VA=="],
|
||||||
|
|
||||||
"@types/node": ["@types/node@25.3.2", "", { "dependencies": { "undici-types": "~7.18.0" } }, "sha512-RpV6r/ij22zRRdyBPcxDeKAzH43phWVKEjL2iksqo1Vz3CuBUrgmPpPhALKiRfU7OMCmeeO9vECBMsV0hMTG8Q=="],
|
"@types/node": ["@types/node@25.3.1", "", { "dependencies": { "undici-types": "~7.18.0" } }, "sha512-hj9YIJimBCipHVfHKRMnvmHg+wfhKc0o4mTtXh9pKBjC8TLJzz0nzGmLi5UJsYAUgSvXFHgb0V2oY10DUFtImw=="],
|
||||||
|
|
||||||
"@types/react": ["@types/react@19.2.14", "", { "dependencies": { "csstype": "^3.2.2" } }, "sha512-ilcTH/UniCkMdtexkoCN0bI7pMcJDvmQFPvuPvmEaYA/NSfFTAgdUSLAoVjaRJm7+6PvcM+q1zYOwS4wTYMF9w=="],
|
"@types/react": ["@types/react@19.2.14", "", { "dependencies": { "csstype": "^3.2.2" } }, "sha512-ilcTH/UniCkMdtexkoCN0bI7pMcJDvmQFPvuPvmEaYA/NSfFTAgdUSLAoVjaRJm7+6PvcM+q1zYOwS4wTYMF9w=="],
|
||||||
|
|
||||||
|
|||||||
@@ -43,7 +43,7 @@
|
|||||||
"devDependencies": {
|
"devDependencies": {
|
||||||
"@eslint/js": "^10.0.1",
|
"@eslint/js": "^10.0.1",
|
||||||
"@tanstack/eslint-plugin-query": "^5.91.4",
|
"@tanstack/eslint-plugin-query": "^5.91.4",
|
||||||
"@types/node": "^25.3.2",
|
"@types/node": "^25.3.1",
|
||||||
"@types/react": "^19.2.14",
|
"@types/react": "^19.2.14",
|
||||||
"@types/react-dom": "^19.2.3",
|
"@types/react-dom": "^19.2.3",
|
||||||
"@vitejs/plugin-react": "^5.1.4",
|
"@vitejs/plugin-react": "^5.1.4",
|
||||||
|
|||||||
@@ -21,6 +21,7 @@ export const DomainWarning = (props: Props) => {
|
|||||||
const { search } = useLocation();
|
const { search } = useLocation();
|
||||||
|
|
||||||
const searchParams = new URLSearchParams(search);
|
const searchParams = new URLSearchParams(search);
|
||||||
|
const redirectUri = searchParams.get("redirect_uri");
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<Card role="alert" aria-live="assertive">
|
<Card role="alert" aria-live="assertive">
|
||||||
@@ -45,7 +46,9 @@ export const DomainWarning = (props: Props) => {
|
|||||||
<CardFooter className="flex flex-col items-stretch gap-3">
|
<CardFooter className="flex flex-col items-stretch gap-3">
|
||||||
<Button
|
<Button
|
||||||
onClick={() =>
|
onClick={() =>
|
||||||
window.location.assign(`${appUrl}/login?${searchParams.toString()}`)
|
window.location.assign(
|
||||||
|
`${appUrl}/login?redirect_uri=${encodeURIComponent(redirectUri || "")}`,
|
||||||
|
)
|
||||||
}
|
}
|
||||||
variant="outline"
|
variant="outline"
|
||||||
>
|
>
|
||||||
|
|||||||
@@ -71,7 +71,7 @@
|
|||||||
"authorizeErrorClientInfo": "Une erreur est survenue lors du chargement des informations du client. Veuillez réessayer plus tard.",
|
"authorizeErrorClientInfo": "Une erreur est survenue lors du chargement des informations du client. Veuillez réessayer plus tard.",
|
||||||
"authorizeErrorMissingParams": "Les paramètres suivants sont manquants : {{missingParams}}",
|
"authorizeErrorMissingParams": "Les paramètres suivants sont manquants : {{missingParams}}",
|
||||||
"openidScopeName": "Connexion OpenID",
|
"openidScopeName": "Connexion OpenID",
|
||||||
"openidScopeDescription": "Autorise l'application à accéder à vos informations \"OpenID Connect\".",
|
"openidScopeDescription": "Allows the app to access your OpenID Connect information.",
|
||||||
"emailScopeName": "Email",
|
"emailScopeName": "Email",
|
||||||
"emailScopeDescription": "Autorise l'application à accéder à votre adresse e-mail.",
|
"emailScopeDescription": "Autorise l'application à accéder à votre adresse e-mail.",
|
||||||
"profileScopeName": "Profil",
|
"profileScopeName": "Profil",
|
||||||
|
|||||||
@@ -51,7 +51,7 @@
|
|||||||
"forgotPasswordTitle": "Забули пароль?",
|
"forgotPasswordTitle": "Забули пароль?",
|
||||||
"failedToFetchProvidersTitle": "Не вдалося завантажити провайдерів автентифікації. Будь ласка, перевірте вашу конфігурацію.",
|
"failedToFetchProvidersTitle": "Не вдалося завантажити провайдерів автентифікації. Будь ласка, перевірте вашу конфігурацію.",
|
||||||
"errorTitle": "Виникла помилка",
|
"errorTitle": "Виникла помилка",
|
||||||
"errorSubtitleInfo": "Під час обробки запиту сталась помилка:",
|
"errorSubtitleInfo": "The following error occurred while processing your request:",
|
||||||
"errorSubtitle": "An error occurred while trying to perform this action. Please check the console for more information.",
|
"errorSubtitle": "An error occurred while trying to perform this action. Please check the console for more information.",
|
||||||
"forgotPasswordMessage": "Ви можете скинути пароль, змінивши змінну середовища \"USERS\".",
|
"forgotPasswordMessage": "Ви можете скинути пароль, змінивши змінну середовища \"USERS\".",
|
||||||
"fieldRequired": "Це поле обов'язкове для заповнення",
|
"fieldRequired": "Це поле обов'язкове для заповнення",
|
||||||
@@ -60,22 +60,22 @@
|
|||||||
"domainWarningSubtitle": "Даний ресурс налаштований для доступу з <code>{{appUrl}}</code>, але використовується <code>{{currentUrl}}</code>. Якщо ви продовжите, можуть виникнути проблеми з автентифікацією.",
|
"domainWarningSubtitle": "Даний ресурс налаштований для доступу з <code>{{appUrl}}</code>, але використовується <code>{{currentUrl}}</code>. Якщо ви продовжите, можуть виникнути проблеми з автентифікацією.",
|
||||||
"ignoreTitle": "Ігнорувати",
|
"ignoreTitle": "Ігнорувати",
|
||||||
"goToCorrectDomainTitle": "Перейти за коректним доменом",
|
"goToCorrectDomainTitle": "Перейти за коректним доменом",
|
||||||
"authorizeTitle": "Авторизуватись",
|
"authorizeTitle": "Authorize",
|
||||||
"authorizeCardTitle": "Перейти до {{app}}?",
|
"authorizeCardTitle": "Continue to {{app}}?",
|
||||||
"authorizeSubtitle": "Чи хочете ви продовжити роботу з цим додатком? Будь ласка, уважно перегляньте дозволи, які вимагає додаток.",
|
"authorizeSubtitle": "Would you like to continue to this app? Please carefully review the permissions requested by the app.",
|
||||||
"authorizeSubtitleOAuth": "Бажаєте продовжити роботу з цим додатком?",
|
"authorizeSubtitleOAuth": "Would you like to continue to this app?",
|
||||||
"authorizeLoadingTitle": "Завантаження...",
|
"authorizeLoadingTitle": "Loading...",
|
||||||
"authorizeLoadingSubtitle": "Будь ласка, зачекайте, поки ми завантажуємо клієнтську інформацію.",
|
"authorizeLoadingSubtitle": "Please wait while we load the client information.",
|
||||||
"authorizeSuccessTitle": "Авторизовано",
|
"authorizeSuccessTitle": "Authorized",
|
||||||
"authorizeSuccessSubtitle": "Вас буде перенаправлено до програми за декілька секунд.",
|
"authorizeSuccessSubtitle": "You will be redirected to the app in a few seconds.",
|
||||||
"authorizeErrorClientInfo": "Під час завантаження даних клієнта сталася помилка. Будь ласка, спробуйте ще раз пізніше.",
|
"authorizeErrorClientInfo": "An error occurred while loading the client information. Please try again later.",
|
||||||
"authorizeErrorMissingParams": "Відсутні наступні параметри: {{missingParams}}",
|
"authorizeErrorMissingParams": "The following parameters are missing: {{missingParams}}",
|
||||||
"openidScopeName": "OpenID Connect",
|
"openidScopeName": "OpenID Connect",
|
||||||
"openidScopeDescription": "Дозволяє програмі отримувати доступ до вашої інформації OpenID Connect.",
|
"openidScopeDescription": "Allows the app to access your OpenID Connect information.",
|
||||||
"emailScopeName": "Електронна пошта",
|
"emailScopeName": "Email",
|
||||||
"emailScopeDescription": "Дозволяє програмі отримувати доступ до вашої адреси електронної пошти.",
|
"emailScopeDescription": "Allows the app to access your email address.",
|
||||||
"profileScopeName": "Профіль",
|
"profileScopeName": "Profile",
|
||||||
"profileScopeDescription": "Дозволяє програмі отримувати доступ до інформації вашого профілю.",
|
"profileScopeDescription": "Allows the app to access your profile information.",
|
||||||
"groupsScopeName": "Групи",
|
"groupsScopeName": "Groups",
|
||||||
"groupsScopeDescription": "Дозволяє програмі отримувати доступ до інформації про групу."
|
"groupsScopeDescription": "Allows the app to access your group information."
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -41,15 +41,11 @@ var (
|
|||||||
)
|
)
|
||||||
|
|
||||||
type ClaimSet struct {
|
type ClaimSet struct {
|
||||||
Iss string `json:"iss"`
|
Iss string `json:"iss"`
|
||||||
Aud string `json:"aud"`
|
Aud string `json:"aud"`
|
||||||
Sub string `json:"sub"`
|
Sub string `json:"sub"`
|
||||||
Iat int64 `json:"iat"`
|
Iat int64 `json:"iat"`
|
||||||
Exp int64 `json:"exp"`
|
Exp int64 `json:"exp"`
|
||||||
Name string `json:"name,omitempty"`
|
|
||||||
Email string `json:"email,omitempty"`
|
|
||||||
PreferredUsername string `json:"preferred_username,omitempty"`
|
|
||||||
Groups []string `json:"groups,omitempty"`
|
|
||||||
}
|
}
|
||||||
|
|
||||||
type UserinfoResponse struct {
|
type UserinfoResponse struct {
|
||||||
@@ -57,7 +53,7 @@ type UserinfoResponse struct {
|
|||||||
Name string `json:"name"`
|
Name string `json:"name"`
|
||||||
Email string `json:"email"`
|
Email string `json:"email"`
|
||||||
PreferredUsername string `json:"preferred_username"`
|
PreferredUsername string `json:"preferred_username"`
|
||||||
Groups []string `json:"groups,omitempty"`
|
Groups []string `json:"groups"`
|
||||||
UpdatedAt int64 `json:"updated_at"`
|
UpdatedAt int64 `json:"updated_at"`
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -353,7 +349,7 @@ func (service *OIDCService) GetCodeEntry(c *gin.Context, codeHash string) (repos
|
|||||||
return oidcCode, nil
|
return oidcCode, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func (service *OIDCService) generateIDToken(client config.OIDCClientConfig, user repository.OidcUserinfo, scope string) (string, error) {
|
func (service *OIDCService) generateIDToken(client config.OIDCClientConfig, sub string) (string, error) {
|
||||||
createdAt := time.Now().Unix()
|
createdAt := time.Now().Unix()
|
||||||
expiresAt := time.Now().Add(time.Duration(service.config.SessionExpiry) * time.Second).Unix()
|
expiresAt := time.Now().Add(time.Duration(service.config.SessionExpiry) * time.Second).Unix()
|
||||||
|
|
||||||
@@ -371,18 +367,12 @@ func (service *OIDCService) generateIDToken(client config.OIDCClientConfig, user
|
|||||||
return "", err
|
return "", err
|
||||||
}
|
}
|
||||||
|
|
||||||
userInfo := service.CompileUserinfo(user, scope)
|
|
||||||
|
|
||||||
claims := ClaimSet{
|
claims := ClaimSet{
|
||||||
Iss: service.issuer,
|
Iss: service.issuer,
|
||||||
Aud: client.ClientID,
|
Aud: client.ClientID,
|
||||||
Sub: user.Sub,
|
Sub: sub,
|
||||||
Iat: createdAt,
|
Iat: createdAt,
|
||||||
Exp: expiresAt,
|
Exp: expiresAt,
|
||||||
Name: userInfo.Name,
|
|
||||||
Email: userInfo.Email,
|
|
||||||
PreferredUsername: userInfo.PreferredUsername,
|
|
||||||
Groups: userInfo.Groups,
|
|
||||||
}
|
}
|
||||||
|
|
||||||
payload, err := json.Marshal(claims)
|
payload, err := json.Marshal(claims)
|
||||||
@@ -407,13 +397,7 @@ func (service *OIDCService) generateIDToken(client config.OIDCClientConfig, user
|
|||||||
}
|
}
|
||||||
|
|
||||||
func (service *OIDCService) GenerateAccessToken(c *gin.Context, client config.OIDCClientConfig, sub string, scope string) (TokenResponse, error) {
|
func (service *OIDCService) GenerateAccessToken(c *gin.Context, client config.OIDCClientConfig, sub string, scope string) (TokenResponse, error) {
|
||||||
user, err := service.GetUserinfo(c, sub)
|
idToken, err := service.generateIDToken(client, sub)
|
||||||
|
|
||||||
if err != nil {
|
|
||||||
return TokenResponse{}, err
|
|
||||||
}
|
|
||||||
|
|
||||||
idToken, err := service.generateIDToken(client, user, scope)
|
|
||||||
|
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return TokenResponse{}, err
|
return TokenResponse{}, err
|
||||||
@@ -472,15 +456,9 @@ func (service *OIDCService) RefreshAccessToken(c *gin.Context, refreshToken stri
|
|||||||
return TokenResponse{}, ErrInvalidClient
|
return TokenResponse{}, ErrInvalidClient
|
||||||
}
|
}
|
||||||
|
|
||||||
user, err := service.GetUserinfo(c, entry.Sub)
|
|
||||||
|
|
||||||
if err != nil {
|
|
||||||
return TokenResponse{}, err
|
|
||||||
}
|
|
||||||
|
|
||||||
idToken, err := service.generateIDToken(config.OIDCClientConfig{
|
idToken, err := service.generateIDToken(config.OIDCClientConfig{
|
||||||
ClientID: entry.ClientID,
|
ClientID: entry.ClientID,
|
||||||
}, user, entry.Scope)
|
}, entry.Sub)
|
||||||
|
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return TokenResponse{}, err
|
return TokenResponse{}, err
|
||||||
|
|||||||
Reference in New Issue
Block a user