Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: oauth revamp + support for multiple grant types in oauth #3885

Merged
merged 27 commits into from Mar 19, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
27 commits
Select commit Hold shift + click to select a range
f761e42
feat: oauth revamp with grant types
amk-dev Mar 9, 2024
41e582f
fix: resolve type error
jamesgeorge007 Mar 12, 2024
2ed6d82
fix: prevent exceptions with OAuth 2.0 Auth Type under GQL
jamesgeorge007 Mar 12, 2024
bc2c0e0
fix: ensure the fields for Basic & Bearer Auth Types are displayed
jamesgeorge007 Mar 12, 2024
d749846
fix: ensure the access token is set for the tab where the request ori…
jamesgeorge007 Mar 13, 2024
2b372e3
fix: account for values referred via request variables under OAuth 2.…
jamesgeorge007 Mar 13, 2024
57c1161
chore: support OAuth 2.0 flow in the collection level authorization/h…
jamesgeorge007 Mar 14, 2024
e743f8d
chore: extend OAuth 2.0 flow support to GraphQL
jamesgeorge007 Mar 14, 2024
a3deafa
feat: add ability to specify access token via request headers/query p…
jamesgeorge007 Mar 14, 2024
fcde2ef
fix: prevent schema validation errors
jamesgeorge007 Mar 14, 2024
4db25e2
fix: ensure updates made to field values are saved
jamesgeorge007 Mar 14, 2024
32a5c84
fix: ensure environment variables referred to in the fields are prese…
jamesgeorge007 Mar 15, 2024
7138887
chore: ensure the Authorization is set as the active tab in the modal…
jamesgeorge007 Mar 15, 2024
ecd68b3
chore: clean up unwanted comments
amk-dev Mar 15, 2024
716034a
chore: use enums instead of string for auth.addTo + use a v-for inste…
amk-dev Mar 15, 2024
dc6d6c1
fix: use a default value for addTo
amk-dev Mar 15, 2024
82e37aa
refactor: cleanup if statements
amk-dev Mar 15, 2024
08cb026
chore: clean up
amk-dev Mar 15, 2024
0b29592
chore: improve naming
amk-dev Mar 18, 2024
1964aad
chore: improve types
amk-dev Mar 18, 2024
4a0a802
refactor: oauth flow in collection properties
amk-dev Mar 19, 2024
bb95f93
chore: cleanups
amk-dev Mar 19, 2024
438d01e
chore: resolve type errors
jamesgeorge007 Mar 19, 2024
556a57f
chore: cleanup
jamesgeorge007 Mar 19, 2024
c73f6bd
test: fix failing tests
jamesgeorge007 Mar 19, 2024
4d52fc8
chore: remove unused imports
amk-dev Mar 19, 2024
f6f758c
fix: fix typo in v2 schema
amk-dev Mar 19, 2024
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
Expand Up @@ -17,7 +17,7 @@
"folders": [],
"requests": [
{
"v": "2",
"v": "3",
"endpoint": "https://echo.hoppscotch.io",
"name": "RequestD",
"params": [],
Expand Down Expand Up @@ -53,7 +53,7 @@
],
"requests": [
{
"v": "2",
"v": "3",
"endpoint": "https://echo.hoppscotch.io",
"name": "RequestC",
"params": [],
Expand Down Expand Up @@ -90,7 +90,7 @@
],
"requests": [
{
"v": "2",
"v": "3",
"endpoint": "https://echo.hoppscotch.io",
"name": "RequestB",
"params": [],
Expand Down Expand Up @@ -119,7 +119,7 @@
],
"requests": [
{
"v": "2",
"v": "3",
"endpoint": "https://echo.hoppscotch.io",
"name": "RequestA",
"params": [],
Expand Down Expand Up @@ -162,7 +162,7 @@
"folders": [],
"requests": [
{
"v": "2",
"v": "3",
"endpoint": "https://echo.hoppscotch.io",
"name": "RequestB",
"params": [],
Expand Down Expand Up @@ -191,7 +191,7 @@
],
"requests": [
{
"v": "2",
"v": "3",
"endpoint": "https://echo.hoppscotch.io",
"name": "RequestA",
"params": [],
Expand Down
Expand Up @@ -4,7 +4,7 @@
"folders": [],
"requests": [
{
"v": "2",
"v": "3",
"endpoint": "<<URL>>",
"name": "test1",
"params": [],
Expand Down
Expand Up @@ -5,40 +5,34 @@
"folders": [],
"requests": [
{
"v": "2",
"v": "3",
"endpoint": "https://echo.hoppscotch.io/<<HEADERS_TYPE1>>",
"name": "",
"params": [],
"headers": [],
"method": "GET",
"auth": {
"authType": "none",
"authActive": true,
"addTo": "Headers",
"key": "",
"value": ""
"authActive": true
},
"preRequestScript": "pw.env.set(\"HEADERS_TYPE1\", \"devblin_local1\");",
"testScript": "// Check status code is 200\npwd.test(\"Status code is 200\", ()=> {\n pw.expect(pw.response.status).toBe(200);\n});\n\n// Check JSON response property\npw.test(\"Check JSON response property\", ()=> {\n pw.expect(pw.response.body.method).toBe(\"GET\");\n pw.expect(pw.response.body.headers).toBeType(\"string\");\n});",
"body": {
"contentType": "application/json",
"body": "{\n\"test\": \"<<HEADERS_TYPE1>>\"\n}"
},
"requestVariables": [],
"requestVariables": []
},
{
"v": "2",
"v": "3",
"endpoint": "https://echo.hoppscotch.dio/<<HEADERS_TYPE2>>",
"name": "success",
"params": [],
"headers": [],
"method": "GET",
"auth": {
"authType": "none",
"authActive": true,
"addTo": "Headers",
"key": "",
"value": ""
"authActive": true
},
"preRequestScript": "pw.env.setd(\"HEADERS_TYPE2\", \"devblin_local2\");",
"testScript": "// Check status code is 200\npw.test(\"Status code is 200\", ()=> {\n pw.expect(pw.response.status).toBe(300);\n});\n\n// Check JSON response property\npw.test(\"Check JSON response property\", ()=> {\n pw.expect(pw.response.body.method).toBe(\"GET\");\n pw.expect(pw.response.body.headers).toBeType(\"object\");\n});",
Expand Down
Expand Up @@ -4,18 +4,15 @@
"folders": [],
"requests":
{
"v": "2",
"v": "3",
"endpoint": "https://echo.hoppscotch.io/<<HEADERS_TYPE1>>",
"name": "fail",
"params": [],
"headers": [],
"method": "GET",
"auth": {
"authType": "none",
"authActive": true,
"addTo": "Headers",
"key": "",
"value": ""
"authActive": true
},
"preRequestScript": "pw.env.set(\"HEADERS_TYPE1\", \"devblin_local1\");",
"testScript": "// Check status code is 200\npw.test(\"Status code is 200\", ()=> {\n pw.expect(pw.response.status).toBe(200);\n});\n\n// Check JSON response property\npw.test(\"Check JSON response property\", ()=> {\n pw.expect(pw.response.body.method).toBe(\"GET\");\n pw.expect(pw.response.body.headers).toBeType(\"string\");\n});",
Expand All @@ -26,18 +23,15 @@
"requestVariables": [],
},
{
"v": "2",
"v": "3",
"endpoint": "https://echo.hoppscotch.io/<<HEADERS_TYPE2>>",
"name": "success",
"params": [],
"headers": [],
"method": "GET",
"auth": {
"authType": "none",
"authActive": true,
"addTo": "Headers",
"key": "",
"value": ""
"authActive": true
},
"preRequestScript": "pw.env.set(\"HEADERS_TYPE2\", \"devblin_local2\");",
"testScript": "// Check status code is 200\npw.test(\"Status code is 200\", ()=> {\n pw.expect(pw.response.status).toBe(300);\n});\n\n// Check JSON response property\npw.test(\"Check JSON response property\", ()=> {\n pw.expect(pw.response.body.method).toBe(\"GET\");\n pw.expect(pw.response.body.headers).toBeType(\"object\");\n});",
Expand Down
Expand Up @@ -5,18 +5,15 @@
"folders": [],
"requests": [
{
"v": "2",
"v": "3",
"endpoint": "https://echo.hoppscotch.io/<<HEADERS_TYPE1>>",
"name": "",
"params": [],
"headers": [],
"method": "GET",
"auth": {
"authType": "none",
"authActive": true,
"addTo": "Headers",
"key": "",
"value": ""
"authActive": true
},
"preRequestScript": "pw.env.set(\"HEADERS_TYPE1\", \"devblin_local1\");",
"testScript": "// Check status code is 200\npw.test(\"Status code is 200\", ()=> {\n pw.expect(pw.response.status).toBe(200);\n});\n\n// Check JSON response property\npw.test(\"Check JSON response property\", ()=> {\n pw.expect(pw.response.body.method).toBe(\"GET\");\n pw.expect(pw.response.body.headers).toBeType(\"object\");\n});",
Expand All @@ -27,18 +24,15 @@
"requestVariables": []
},
{
"v": "2",
"v": "3",
"endpoint": "https://echo.hoppscotch.io/<<HEADERS_TYPE2>>",
"name": "success",
"params": [],
"headers": [],
"method": "GET",
"auth": {
"authType": "none",
"authActive": true,
"addTo": "Headers",
"key": "",
"value": ""
"authActive": true
},
"preRequestScript": "pw.env.set(\"HEADERS_TYPE2\", \"devblin_local2\");",
"testScript": "// Check status code is 200\npw.test(\"Status code is 200\", ()=> {\n pw.expect(pw.response.status).toBe(200);\n});\n\n// Check JSON response property\npw.test(\"Check JSON response property\", ()=> {\n pw.expect(pw.response.body.method).toBe(\"GET\");\n pw.expect(pw.response.body.headers).toBeType(\"object\");\n});",
Expand Down
Expand Up @@ -4,7 +4,7 @@
"folders": [],
"requests": [
{
"v": "2",
"v": "3",
"auth": { "authType": "none", "authActive": true },
"body": { "body": null, "contentType": null },
"name": "sample-req",
Expand Down
Expand Up @@ -4,7 +4,7 @@
"folders": [],
"requests": [
{
"v": "2",
"v": "3",
"name": "test-request",
"endpoint": "https://echo.hoppscotch.io",
"method": "POST",
Expand Down
Expand Up @@ -4,7 +4,7 @@
"folders": [],
"requests": [
{
"v": "2",
"v": "3",
"auth": { "authType": "none", "authActive": true },
"body": { "body": null, "contentType": null },
"name": "test-secret-headers",
Expand All @@ -23,7 +23,7 @@
"preRequestScript": "const secretHeaderValueFromPreReqScript = pw.env.get(\"secretHeaderValue\")\npw.env.set(\"secretHeaderValueFromPreReqScript\", secretHeaderValueFromPreReqScript)"
},
{
"v": "2",
"v": "3",
"auth": { "authType": "none", "authActive": true },
"body": {
"body": "{\n \"secretBodyKey\": \"<<secretBodyValue>>\"\n}",
Expand All @@ -39,7 +39,7 @@
"preRequestScript": "const secretBodyValueFromPreReqScript = pw.env.get(\"secretBodyValue\")\npw.env.set(\"secretBodyValueFromPreReqScript\", secretBodyValueFromPreReqScript)"
},
{
"v": "2",
"v": "3",
"auth": { "authType": "none", "authActive": true },
"body": { "body": null, "contentType": null },
"name": "test-secret-query-params",
Expand All @@ -58,7 +58,7 @@
"preRequestScript": "const secretQueryParamValueFromPreReqScript = pw.env.get(\"secretQueryParamValue\")\npw.env.set(\"secretQueryParamValueFromPreReqScript\", secretQueryParamValueFromPreReqScript)"
},
{
"v": "2",
"v": "3",
"auth": {
"authType": "basic",
"password": "<<secretBasicAuthPassword>>",
Expand All @@ -76,7 +76,7 @@
"preRequestScript": ""
},
{
"v": "2",
"v": "3",
"auth": {
"token": "<<secretBearerToken>>",
"authType": "bearer",
Expand All @@ -95,7 +95,7 @@
"preRequestScript": "const secretBearerToken = pw.env.get(\"secretBearerToken\")\npw.env.set(\"preReqSecretBearerToken\", secretBearerToken)"
},
{
"v": "2",
"v": "3",
"auth": { "authType": "none", "authActive": true },
"body": { "body": null, "contentType": null },
"name": "test-secret-fallback",
Expand Down
Expand Up @@ -4,7 +4,7 @@
"folders": [],
"requests": [
{
"v": "2",
"v": "3",
"auth": {
"authType": "none",
"authActive": true
Expand All @@ -29,7 +29,7 @@
"preRequestScript": "pw.env.set(\"secretHeaderValue\", \"secret-header-value\")\n\nconst secretHeaderValueFromPreReqScript = pw.env.getResolve(\"secretHeaderValue\")\npw.env.set(\"secretHeaderValueFromPreReqScript\", secretHeaderValueFromPreReqScript)"
},
{
"v": "2",
"v": "3",
"auth": {
"authType": "none",
"authActive": true
Expand All @@ -54,7 +54,7 @@
"preRequestScript": "pw.env.set(\"secretHeaderValue\", \"secret-header-value-overriden\")\n\nconst secretHeaderValueFromPreReqScript = pw.env.getResolve(\"secretHeaderValue\")\npw.env.set(\"secretHeaderValueFromPreReqScript\", secretHeaderValueFromPreReqScript)"
},
{
"v": "2",
"v": "3",
"auth": {
"authType": "none",
"authActive": true
Expand All @@ -73,7 +73,7 @@
"preRequestScript": "const secretBodyValue = pw.env.get(\"secretBodyValue\")\n\nif (!secretBodyValue) { \n pw.env.set(\"secretBodyValue\", \"secret-body-value\")\n}\n\nconst secretBodyValueFromPreReqScript = pw.env.get(\"secretBodyValue\")\npw.env.set(\"secretBodyValueFromPreReqScript\", secretBodyValueFromPreReqScript)"
},
{
"v": "2",
"v": "3",
"auth": {
"authType": "none",
"authActive": true
Expand All @@ -98,7 +98,7 @@
"preRequestScript": "const secretQueryParamValue = pw.env.get(\"secretQueryParamValue\")\n\nif (!secretQueryParamValue) {\n pw.env.set(\"secretQueryParamValue\", \"secret-query-param-value\")\n}\n\nconst secretQueryParamValueFromPreReqScript = pw.env.get(\"secretQueryParamValue\")\npw.env.set(\"secretQueryParamValueFromPreReqScript\", secretQueryParamValueFromPreReqScript)"
},
{
"v": "2",
"v": "3",
"auth": {
"authType": "basic",
"password": "<<secretBasicAuthPassword>>",
Expand All @@ -119,7 +119,7 @@
"preRequestScript": "let secretBasicAuthUsername = pw.env.get(\"secretBasicAuthUsername\")\n\nlet secretBasicAuthPassword = pw.env.get(\"secretBasicAuthPassword\")\n\nif (!secretBasicAuthUsername) {\n pw.env.set(\"secretBasicAuthUsername\", \"test-user\")\n}\n\nif (!secretBasicAuthPassword) {\n pw.env.set(\"secretBasicAuthPassword\", \"test-pass\")\n}"
},
{
"v": "2",
"v": "3",
"auth": {
"token": "<<secretBearerToken>>",
"authType": "bearer",
Expand Down
Expand Up @@ -4,7 +4,7 @@
"folders": [],
"requests": [
{
"v": "2",
"v": "3",
"endpoint": "https://httpbin.org/post",
"name": "req",
"params": [],
Expand Down
13 changes: 9 additions & 4 deletions packages/hoppscotch-cli/src/options/test/env.ts
Expand Up @@ -6,7 +6,7 @@ import { error } from "../../types/errors";
import {
HoppEnvKeyPairObject,
HoppEnvPair,
HoppEnvs
HoppEnvs,
} from "../../types/request";
import { readJsonFile } from "../../utils/mutators";

Expand All @@ -17,7 +17,7 @@ import { readJsonFile } from "../../utils/mutators";
*/
export async function parseEnvsData(path: string) {
const contents = await readJsonFile(path);
const envPairs: Array<Environment["variables"][number] | HoppEnvPair> = [];
const envPairs: Array<HoppEnvPair | Record<string, string>> = [];

// The legacy key-value pair format that is still supported
const HoppEnvKeyPairResult = HoppEnvKeyPairObject.safeParse(contents);
Expand All @@ -26,7 +26,9 @@ export async function parseEnvsData(path: string) {
const HoppEnvExportObjectResult = Environment.safeParse(contents);

// Shape of the bulk environment export object that is exported from the app
const HoppBulkEnvExportObjectResult = z.array(entityReference(Environment)).safeParse(contents)
const HoppBulkEnvExportObjectResult = z
.array(entityReference(Environment))
.safeParse(contents);

// CLI doesnt support bulk environments export
// Hence we check for this case and throw an error if it matches the format
Expand All @@ -36,7 +38,10 @@ export async function parseEnvsData(path: string) {

// Checks if the environment file is of the correct format
// If it doesnt match either of them, we throw an error
if (!HoppEnvKeyPairResult.success && HoppEnvExportObjectResult.type === "err") {
if (
!HoppEnvKeyPairResult.success &&
HoppEnvExportObjectResult.type === "err"
) {
throw error({ code: "MALFORMED_ENV_FILE", path, data: error });
}

Expand Down