First upload version 0.0.1
This commit is contained in:
13
node_modules/@octokit/oauth-app/dist-src/middleware/aws-lambda/api-gateway-v2-parse-request.js
generated
vendored
Normal file
13
node_modules/@octokit/oauth-app/dist-src/middleware/aws-lambda/api-gateway-v2-parse-request.js
generated
vendored
Normal file
@@ -0,0 +1,13 @@
|
||||
function parseRequest(request) {
|
||||
const { method } = request.requestContext.http;
|
||||
let url = request.rawPath;
|
||||
const { stage } = request.requestContext;
|
||||
if (url.startsWith("/" + stage)) url = url.substring(stage.length + 1);
|
||||
if (request.rawQueryString) url += "?" + request.rawQueryString;
|
||||
const headers = request.headers;
|
||||
const text = async () => request.body || "";
|
||||
return { method, url, headers, text };
|
||||
}
|
||||
export {
|
||||
parseRequest
|
||||
};
|
||||
10
node_modules/@octokit/oauth-app/dist-src/middleware/aws-lambda/api-gateway-v2-send-response.js
generated
vendored
Normal file
10
node_modules/@octokit/oauth-app/dist-src/middleware/aws-lambda/api-gateway-v2-send-response.js
generated
vendored
Normal file
@@ -0,0 +1,10 @@
|
||||
function sendResponse(octokitResponse) {
|
||||
return {
|
||||
statusCode: octokitResponse.status,
|
||||
headers: octokitResponse.headers,
|
||||
body: octokitResponse.text
|
||||
};
|
||||
}
|
||||
export {
|
||||
sendResponse
|
||||
};
|
||||
13
node_modules/@octokit/oauth-app/dist-src/middleware/aws-lambda/api-gateway-v2.js
generated
vendored
Normal file
13
node_modules/@octokit/oauth-app/dist-src/middleware/aws-lambda/api-gateway-v2.js
generated
vendored
Normal file
@@ -0,0 +1,13 @@
|
||||
import { parseRequest } from "./api-gateway-v2-parse-request.js";
|
||||
import { sendResponse } from "./api-gateway-v2-send-response.js";
|
||||
import { handleRequest } from "../handle-request.js";
|
||||
function createAWSLambdaAPIGatewayV2Handler(app, options = {}) {
|
||||
return async function(event) {
|
||||
const request = parseRequest(event);
|
||||
const response = await handleRequest(app, options, request);
|
||||
return response ? sendResponse(response) : void 0;
|
||||
};
|
||||
}
|
||||
export {
|
||||
createAWSLambdaAPIGatewayV2Handler
|
||||
};
|
||||
240
node_modules/@octokit/oauth-app/dist-src/middleware/handle-request.js
generated
vendored
Normal file
240
node_modules/@octokit/oauth-app/dist-src/middleware/handle-request.js
generated
vendored
Normal file
@@ -0,0 +1,240 @@
|
||||
import { OAuthApp } from "../index.js";
|
||||
import { unknownRouteResponse } from "./unknown-route-response.js";
|
||||
async function handleRequest(app, { pathPrefix = "/api/github/oauth" }, request) {
|
||||
let { pathname } = new URL(request.url, "http://localhost");
|
||||
if (!pathname.startsWith(`${pathPrefix}/`)) {
|
||||
return void 0;
|
||||
}
|
||||
if (request.method === "OPTIONS") {
|
||||
return {
|
||||
status: 200,
|
||||
headers: {
|
||||
"access-control-allow-origin": "*",
|
||||
"access-control-allow-methods": "*",
|
||||
"access-control-allow-headers": "Content-Type, User-Agent, Authorization"
|
||||
}
|
||||
};
|
||||
}
|
||||
pathname = pathname.slice(pathPrefix.length + 1);
|
||||
const route = [request.method, pathname].join(" ");
|
||||
const routes = {
|
||||
getLogin: `GET login`,
|
||||
getCallback: `GET callback`,
|
||||
createToken: `POST token`,
|
||||
getToken: `GET token`,
|
||||
patchToken: `PATCH token`,
|
||||
patchRefreshToken: `PATCH refresh-token`,
|
||||
scopeToken: `POST token/scoped`,
|
||||
deleteToken: `DELETE token`,
|
||||
deleteGrant: `DELETE grant`
|
||||
};
|
||||
if (!Object.values(routes).includes(route)) {
|
||||
return unknownRouteResponse(request);
|
||||
}
|
||||
let json;
|
||||
try {
|
||||
const text = await request.text();
|
||||
json = text ? JSON.parse(text) : {};
|
||||
} catch (error) {
|
||||
return {
|
||||
status: 400,
|
||||
headers: {
|
||||
"content-type": "application/json",
|
||||
"access-control-allow-origin": "*"
|
||||
},
|
||||
text: JSON.stringify({
|
||||
error: "[@octokit/oauth-app] request error"
|
||||
})
|
||||
};
|
||||
}
|
||||
const { searchParams } = new URL(request.url, "http://localhost");
|
||||
const query = Object.fromEntries(searchParams);
|
||||
const headers = request.headers;
|
||||
try {
|
||||
if (route === routes.getLogin) {
|
||||
const authOptions = {};
|
||||
if (query.state) {
|
||||
Object.assign(authOptions, { state: query.state });
|
||||
}
|
||||
if (query.scopes) {
|
||||
Object.assign(authOptions, { scopes: query.scopes.split(",") });
|
||||
}
|
||||
if (query.allowSignup) {
|
||||
Object.assign(authOptions, {
|
||||
allowSignup: query.allowSignup === "true"
|
||||
});
|
||||
}
|
||||
if (query.redirectUrl) {
|
||||
Object.assign(authOptions, { redirectUrl: query.redirectUrl });
|
||||
}
|
||||
const { url } = app.getWebFlowAuthorizationUrl(authOptions);
|
||||
return { status: 302, headers: { location: url } };
|
||||
}
|
||||
if (route === routes.getCallback) {
|
||||
if (query.error) {
|
||||
throw new Error(
|
||||
`[@octokit/oauth-app] ${query.error} ${query.error_description}`
|
||||
);
|
||||
}
|
||||
if (!query.code) {
|
||||
throw new Error('[@octokit/oauth-app] "code" parameter is required');
|
||||
}
|
||||
const {
|
||||
authentication: { token: token2 }
|
||||
} = await app.createToken({
|
||||
code: query.code
|
||||
});
|
||||
return {
|
||||
status: 200,
|
||||
headers: {
|
||||
"content-type": "text/html"
|
||||
},
|
||||
text: `<h1>Token created successfully</h1>
|
||||
|
||||
<p>Your token is: <strong>${token2}</strong>. Copy it now as it cannot be shown again.</p>`
|
||||
};
|
||||
}
|
||||
if (route === routes.createToken) {
|
||||
const { code, redirectUrl } = json;
|
||||
if (!code) {
|
||||
throw new Error('[@octokit/oauth-app] "code" parameter is required');
|
||||
}
|
||||
const result = await app.createToken({
|
||||
code,
|
||||
redirectUrl
|
||||
});
|
||||
delete result.authentication.clientSecret;
|
||||
return {
|
||||
status: 201,
|
||||
headers: {
|
||||
"content-type": "application/json",
|
||||
"access-control-allow-origin": "*"
|
||||
},
|
||||
text: JSON.stringify(result)
|
||||
};
|
||||
}
|
||||
if (route === routes.getToken) {
|
||||
const token2 = headers.authorization?.substr("token ".length);
|
||||
if (!token2) {
|
||||
throw new Error(
|
||||
'[@octokit/oauth-app] "Authorization" header is required'
|
||||
);
|
||||
}
|
||||
const result = await app.checkToken({
|
||||
token: token2
|
||||
});
|
||||
delete result.authentication.clientSecret;
|
||||
return {
|
||||
status: 200,
|
||||
headers: {
|
||||
"content-type": "application/json",
|
||||
"access-control-allow-origin": "*"
|
||||
},
|
||||
text: JSON.stringify(result)
|
||||
};
|
||||
}
|
||||
if (route === routes.patchToken) {
|
||||
const token2 = headers.authorization?.substr("token ".length);
|
||||
if (!token2) {
|
||||
throw new Error(
|
||||
'[@octokit/oauth-app] "Authorization" header is required'
|
||||
);
|
||||
}
|
||||
const result = await app.resetToken({ token: token2 });
|
||||
delete result.authentication.clientSecret;
|
||||
return {
|
||||
status: 200,
|
||||
headers: {
|
||||
"content-type": "application/json",
|
||||
"access-control-allow-origin": "*"
|
||||
},
|
||||
text: JSON.stringify(result)
|
||||
};
|
||||
}
|
||||
if (route === routes.patchRefreshToken) {
|
||||
const token2 = headers.authorization?.substr("token ".length);
|
||||
if (!token2) {
|
||||
throw new Error(
|
||||
'[@octokit/oauth-app] "Authorization" header is required'
|
||||
);
|
||||
}
|
||||
const { refreshToken } = json;
|
||||
if (!refreshToken) {
|
||||
throw new Error(
|
||||
"[@octokit/oauth-app] refreshToken must be sent in request body"
|
||||
);
|
||||
}
|
||||
const result = await app.refreshToken({ refreshToken });
|
||||
delete result.authentication.clientSecret;
|
||||
return {
|
||||
status: 200,
|
||||
headers: {
|
||||
"content-type": "application/json",
|
||||
"access-control-allow-origin": "*"
|
||||
},
|
||||
text: JSON.stringify(result)
|
||||
};
|
||||
}
|
||||
if (route === routes.scopeToken) {
|
||||
const token2 = headers.authorization?.substr("token ".length);
|
||||
if (!token2) {
|
||||
throw new Error(
|
||||
'[@octokit/oauth-app] "Authorization" header is required'
|
||||
);
|
||||
}
|
||||
const result = await app.scopeToken({
|
||||
token: token2,
|
||||
...json
|
||||
});
|
||||
delete result.authentication.clientSecret;
|
||||
return {
|
||||
status: 200,
|
||||
headers: {
|
||||
"content-type": "application/json",
|
||||
"access-control-allow-origin": "*"
|
||||
},
|
||||
text: JSON.stringify(result)
|
||||
};
|
||||
}
|
||||
if (route === routes.deleteToken) {
|
||||
const token2 = headers.authorization?.substr("token ".length);
|
||||
if (!token2) {
|
||||
throw new Error(
|
||||
'[@octokit/oauth-app] "Authorization" header is required'
|
||||
);
|
||||
}
|
||||
await app.deleteToken({
|
||||
token: token2
|
||||
});
|
||||
return {
|
||||
status: 204,
|
||||
headers: { "access-control-allow-origin": "*" }
|
||||
};
|
||||
}
|
||||
const token = headers.authorization?.substr("token ".length);
|
||||
if (!token) {
|
||||
throw new Error(
|
||||
'[@octokit/oauth-app] "Authorization" header is required'
|
||||
);
|
||||
}
|
||||
await app.deleteAuthorization({
|
||||
token
|
||||
});
|
||||
return {
|
||||
status: 204,
|
||||
headers: { "access-control-allow-origin": "*" }
|
||||
};
|
||||
} catch (error) {
|
||||
return {
|
||||
status: 400,
|
||||
headers: {
|
||||
"content-type": "application/json",
|
||||
"access-control-allow-origin": "*"
|
||||
},
|
||||
text: JSON.stringify({ error: error.message })
|
||||
};
|
||||
}
|
||||
}
|
||||
export {
|
||||
handleRequest
|
||||
};
|
||||
19
node_modules/@octokit/oauth-app/dist-src/middleware/node/index.js
generated
vendored
Normal file
19
node_modules/@octokit/oauth-app/dist-src/middleware/node/index.js
generated
vendored
Normal file
@@ -0,0 +1,19 @@
|
||||
import { parseRequest } from "./parse-request.js";
|
||||
import { sendResponse } from "./send-response.js";
|
||||
import { handleRequest } from "../handle-request.js";
|
||||
function createNodeMiddleware(app, options = {}) {
|
||||
return async function(request, response, next) {
|
||||
const octokitRequest = await parseRequest(request);
|
||||
const octokitResponse = await handleRequest(app, options, octokitRequest);
|
||||
if (octokitResponse) {
|
||||
sendResponse(octokitResponse, response);
|
||||
return true;
|
||||
} else {
|
||||
next?.();
|
||||
return false;
|
||||
}
|
||||
};
|
||||
}
|
||||
export {
|
||||
createNodeMiddleware
|
||||
};
|
||||
14
node_modules/@octokit/oauth-app/dist-src/middleware/node/parse-request.js
generated
vendored
Normal file
14
node_modules/@octokit/oauth-app/dist-src/middleware/node/parse-request.js
generated
vendored
Normal file
@@ -0,0 +1,14 @@
|
||||
function parseRequest(request) {
|
||||
const { method, url, headers } = request;
|
||||
async function text() {
|
||||
const text2 = await new Promise((resolve, reject) => {
|
||||
let bodyChunks = [];
|
||||
request.on("error", reject).on("data", (chunk) => bodyChunks.push(chunk)).on("end", () => resolve(Buffer.concat(bodyChunks).toString()));
|
||||
});
|
||||
return text2;
|
||||
}
|
||||
return { method, url, headers, text };
|
||||
}
|
||||
export {
|
||||
parseRequest
|
||||
};
|
||||
7
node_modules/@octokit/oauth-app/dist-src/middleware/node/send-response.js
generated
vendored
Normal file
7
node_modules/@octokit/oauth-app/dist-src/middleware/node/send-response.js
generated
vendored
Normal file
@@ -0,0 +1,7 @@
|
||||
function sendResponse(octokitResponse, response) {
|
||||
response.writeHead(octokitResponse.status, octokitResponse.headers);
|
||||
response.end(octokitResponse.text);
|
||||
}
|
||||
export {
|
||||
sendResponse
|
||||
};
|
||||
12
node_modules/@octokit/oauth-app/dist-src/middleware/unknown-route-response.js
generated
vendored
Normal file
12
node_modules/@octokit/oauth-app/dist-src/middleware/unknown-route-response.js
generated
vendored
Normal file
@@ -0,0 +1,12 @@
|
||||
function unknownRouteResponse(request) {
|
||||
return {
|
||||
status: 404,
|
||||
headers: { "content-type": "application/json" },
|
||||
text: JSON.stringify({
|
||||
error: `Unknown route: ${request.method} ${request.url}`
|
||||
})
|
||||
};
|
||||
}
|
||||
export {
|
||||
unknownRouteResponse
|
||||
};
|
||||
13
node_modules/@octokit/oauth-app/dist-src/middleware/web-worker/index.js
generated
vendored
Normal file
13
node_modules/@octokit/oauth-app/dist-src/middleware/web-worker/index.js
generated
vendored
Normal file
@@ -0,0 +1,13 @@
|
||||
import { parseRequest } from "./parse-request.js";
|
||||
import { sendResponse } from "./send-response.js";
|
||||
import { handleRequest } from "../handle-request.js";
|
||||
function createWebWorkerHandler(app, options = {}) {
|
||||
return async function(request) {
|
||||
const octokitRequest = await parseRequest(request);
|
||||
const octokitResponse = await handleRequest(app, options, octokitRequest);
|
||||
return octokitResponse ? sendResponse(octokitResponse) : void 0;
|
||||
};
|
||||
}
|
||||
export {
|
||||
createWebWorkerHandler
|
||||
};
|
||||
12
node_modules/@octokit/oauth-app/dist-src/middleware/web-worker/parse-request.js
generated
vendored
Normal file
12
node_modules/@octokit/oauth-app/dist-src/middleware/web-worker/parse-request.js
generated
vendored
Normal file
@@ -0,0 +1,12 @@
|
||||
function parseRequest(request) {
|
||||
const headers = Object.fromEntries(request.headers.entries());
|
||||
return {
|
||||
method: request.method,
|
||||
url: request.url,
|
||||
headers,
|
||||
text: () => request.text()
|
||||
};
|
||||
}
|
||||
export {
|
||||
parseRequest
|
||||
};
|
||||
12
node_modules/@octokit/oauth-app/dist-src/middleware/web-worker/send-response.js
generated
vendored
Normal file
12
node_modules/@octokit/oauth-app/dist-src/middleware/web-worker/send-response.js
generated
vendored
Normal file
@@ -0,0 +1,12 @@
|
||||
function sendResponse(octokitResponse) {
|
||||
const responseOptions = {
|
||||
status: octokitResponse.status
|
||||
};
|
||||
if (octokitResponse.headers) {
|
||||
Object.assign(responseOptions, { headers: octokitResponse.headers });
|
||||
}
|
||||
return new Response(octokitResponse.text, responseOptions);
|
||||
}
|
||||
export {
|
||||
sendResponse
|
||||
};
|
||||
Reference in New Issue
Block a user