fix: add i18n entries for oauth errors

This commit is contained in:
Andrew Bastin
2023-11-14 17:44:37 +05:30
parent 8d7509cdea
commit e93a37c711
3 changed files with 64 additions and 3 deletions

View File

@@ -139,7 +139,21 @@
"password": "Password", "password": "Password",
"token": "Token", "token": "Token",
"type": "Authorization Type", "type": "Authorization Type",
"username": "Username" "username": "Username",
"oauth": {
"token_generation_oidc_discovery_failed": "Failure on token generation: OpenID Connect Discovery Failed",
"something_went_wrong_on_token_generation": "Something went wrong on token generation",
"redirect_auth_server_returned_error": "Auth Server returned an error state",
"redirect_no_auth_code": "No Authorization Code present in the redirect",
"redirect_invalid_state": "Invalid State value present in the redirect",
"redirect_no_token_endpoint": "No Token Endpoint Defined",
"redirect_no_client_id": "No Client ID defined",
"redirect_no_client_secret": "No Client Secret Defined",
"redirect_no_code_verifier": "No Code Verifier Defined",
"redirect_auth_token_request_failed": "Request to get the auth token failed",
"redirect_auth_token_request_invalid_response": "Invalid Response from the Token Endpoint when requesting for an auth token",
"something_went_wrong_on_oauth_redirect": "Something went wrong during OAuth Redirect"
}
}, },
"collection": { "collection": {
"created": "Collection created", "created": "Collection created",

View File

@@ -78,6 +78,15 @@ const clientSecret = pluckRef(auth, "clientSecret" as any)
const scope = pluckRef(auth, "scope") const scope = pluckRef(auth, "scope")
function translateTokenRequestError(error: string) {
switch (error) {
case "OIDC_DISCOVERY_FAILED":
return t("authorization.oauth.token_generation_oidc_discovery_failed")
default:
return t("authorization.oauth.something_went_wrong_on_token_generation")
}
}
const handleAccessTokenRequest = async () => { const handleAccessTokenRequest = async () => {
if ( if (
oidcDiscoveryURL.value === "" && oidcDiscoveryURL.value === "" &&
@@ -102,7 +111,7 @@ const handleAccessTokenRequest = async () => {
const res = await tokenRequest(tokenReqParams) const res = await tokenRequest(tokenReqParams)
if (res && E.isLeft(res)) { if (res && E.isLeft(res)) {
toast.error(res.left) toast.error(translateTokenRequestError(res.left))
} }
} catch (e) { } catch (e) {
toast.error(`${e}`) toast.error(`${e}`)

View File

@@ -7,6 +7,7 @@
<script setup lang="ts"> <script setup lang="ts">
import { handleOAuthRedirect } from "~/helpers/oauth" import { handleOAuthRedirect } from "~/helpers/oauth"
import { useToast } from "~/composables/toast" import { useToast } from "~/composables/toast"
import { useI18n } from "~/composables/i18n"
import * as E from "fp-ts/Either" import * as E from "fp-ts/Either"
import { useService } from "dioc/vue" import { useService } from "dioc/vue"
@@ -15,17 +16,54 @@ import { onMounted } from "vue"
import { useRouter } from "vue-router" import { useRouter } from "vue-router"
const t = useI18n()
const router = useRouter() const router = useRouter()
const toast = useToast() const toast = useToast()
const tabs = useService(RESTTabService) const tabs = useService(RESTTabService)
function translateOAuthRedirectError(error: string) {
switch (error) {
case "AUTH_SERVER_RETURNED_ERROR":
return t("authorization.oauth.redirect_auth_server_returned_error")
case "NO_AUTH_CODE":
return t("authorization.oauth.redirect_no_auth_code")
case "INVALID_STATE":
return t("authorization.oauth.redirect_invalid_state")
case "NO_TOKEN_ENDPOINT":
return t("authorization.oauth.redirect_no_token_endpoint")
case "NO_CLIENT_ID":
return t("authorization.oauth.redirect_no_client_id")
case "NO_CLIENT_SECRET":
return t("authorization.oauth.redirect_no_client_secret")
case "NO_CODE_VERIFIER":
return t("authorization.oauth.redirect_no_code_verifier")
case "AUTH_TOKEN_REQUEST_FAILED":
return t("authorization.oauth.redirect_auth_token_request_failed")
case "AUTH_TOKEN_REQUEST_INVALID_RESPONSE":
return t(
"authorization.oauth.redirect_auth_token_request_invalid_response"
)
default:
return t("authorization.oauth.something_went_wrong_on_oauth_redirect")
}
}
onMounted(async () => { onMounted(async () => {
const tokenInfo = await handleOAuthRedirect() const tokenInfo = await handleOAuthRedirect()
if (E.isLeft(tokenInfo)) { if (E.isLeft(tokenInfo)) {
toast.error(tokenInfo.left) toast.error(translateOAuthRedirectError(tokenInfo.left))
router.push("/") router.push("/")
return return
} }