chore: make client secret optional across grant types (#4363)
Co-authored-by: jamesgeorge007 <25279263+jamesgeorge007@users.noreply.github.com>
This commit is contained in:
@@ -401,7 +401,7 @@ const supportedGrantTypes = [
|
||||
return E.right(undefined)
|
||||
}
|
||||
|
||||
const runAction = () => {
|
||||
const runAction = async () => {
|
||||
const params: AuthCodeOauthFlowParams = {
|
||||
authEndpoint: authEndpoint.value,
|
||||
tokenEndpoint: tokenEndpoint.value,
|
||||
@@ -420,7 +420,11 @@ const supportedGrantTypes = [
|
||||
return E.left("VALIDATION_FAILED" as const)
|
||||
}
|
||||
|
||||
authCode.init(parsedArgs.data)
|
||||
const res = await authCode.init(parsedArgs.data)
|
||||
|
||||
if (E.isLeft(res)) {
|
||||
return res
|
||||
}
|
||||
|
||||
return E.right(undefined)
|
||||
}
|
||||
@@ -1047,8 +1051,14 @@ const generateOAuthToken = async () => {
|
||||
VALIDATION_FAILED: t("authorization.oauth.validation_failed"),
|
||||
OAUTH_TOKEN_FETCH_FAILED: t("authorization.oauth.token_fetch_failed"),
|
||||
}
|
||||
if (res.left in errorMessages) {
|
||||
// @ts-expect-error - not possible to have a key that doesn't exist
|
||||
toast.error(errorMessages[res.left])
|
||||
return
|
||||
}
|
||||
|
||||
toast.error(t("error.something_went_wrong"))
|
||||
|
||||
toast.error(errorMessages[res.left])
|
||||
return
|
||||
}
|
||||
}
|
||||
|
||||
@@ -24,7 +24,6 @@ const ClientCredentialsFlowParamsSchema = ClientCredentialsGrantTypeParams.pick(
|
||||
return (
|
||||
params.authEndpoint.length >= 1 &&
|
||||
params.clientID.length >= 1 &&
|
||||
params.clientSecret.length >= 1 &&
|
||||
(!params.scopes || params.scopes.length >= 1)
|
||||
)
|
||||
},
|
||||
@@ -56,7 +55,10 @@ const initClientCredentialsOAuthFlow = async ({
|
||||
const formData = new URLSearchParams()
|
||||
formData.append("grant_type", "client_credentials")
|
||||
formData.append("client_id", clientID)
|
||||
formData.append("client_secret", clientSecret)
|
||||
|
||||
if (clientSecret) {
|
||||
formData.append("client_secret", clientSecret)
|
||||
}
|
||||
|
||||
if (scopes) {
|
||||
formData.append("scope", scopes)
|
||||
|
||||
@@ -24,7 +24,6 @@ const PasswordFlowParamsSchema = PasswordGrantTypeParams.pick({
|
||||
return (
|
||||
params.authEndpoint.length >= 1 &&
|
||||
params.clientID.length >= 1 &&
|
||||
params.clientSecret.length >= 1 &&
|
||||
params.username.length >= 1 &&
|
||||
params.password.length >= 1 &&
|
||||
(!params.scopes || params.scopes.length >= 1)
|
||||
@@ -59,10 +58,13 @@ const initPasswordOauthFlow = async ({
|
||||
const formData = new URLSearchParams()
|
||||
formData.append("grant_type", "password")
|
||||
formData.append("client_id", clientID)
|
||||
formData.append("client_secret", clientSecret)
|
||||
formData.append("username", username)
|
||||
formData.append("password", password)
|
||||
|
||||
if (clientSecret) {
|
||||
formData.append("client_secret", clientSecret)
|
||||
}
|
||||
|
||||
if (scopes) {
|
||||
formData.append("scope", scopes)
|
||||
}
|
||||
|
||||
@@ -25,7 +25,7 @@ const DEFAULT_SETTINGS = getDefaultSettings()
|
||||
|
||||
export const REST_COLLECTIONS_MOCK: HoppCollection[] = [
|
||||
{
|
||||
v: 3,
|
||||
v: 4,
|
||||
name: "Echo",
|
||||
folders: [],
|
||||
requests: [
|
||||
@@ -50,12 +50,12 @@ export const REST_COLLECTIONS_MOCK: HoppCollection[] = [
|
||||
|
||||
export const GQL_COLLECTIONS_MOCK: HoppCollection[] = [
|
||||
{
|
||||
v: 3,
|
||||
v: 4,
|
||||
name: "Echo",
|
||||
folders: [],
|
||||
requests: [
|
||||
{
|
||||
v: 6,
|
||||
v: 7,
|
||||
name: "Echo test",
|
||||
url: "https://echo.hoppscotch.io/graphql",
|
||||
headers: [],
|
||||
@@ -156,7 +156,7 @@ export const GQL_HISTORY_MOCK: GQLHistoryEntry[] = [
|
||||
{
|
||||
v: 1,
|
||||
request: {
|
||||
v: 6,
|
||||
v: 7,
|
||||
name: "Untitled",
|
||||
url: "https://echo.hoppscotch.io/graphql",
|
||||
query: "query Request { url }",
|
||||
@@ -177,7 +177,7 @@ export const GQL_TAB_STATE_MOCK: PersistableTabState<HoppGQLDocument> = {
|
||||
tabID: "5edbe8d4-65c9-4381-9354-5f1bf05d8ccc",
|
||||
doc: {
|
||||
request: {
|
||||
v: 6,
|
||||
v: 7,
|
||||
name: "Untitled",
|
||||
url: "https://echo.hoppscotch.io/graphql",
|
||||
headers: [],
|
||||
|
||||
Reference in New Issue
Block a user