Skip to content

Commit bd788a3

Browse files
authored
Merge pull request #1618 from Swapnil-2001/auth-header
Update files to authenticate with request headers
2 parents 6a84b7b + ef7b3dd commit bd788a3

File tree

3 files changed

+44
-45
lines changed

3 files changed

+44
-45
lines changed

server/scripts/examples-gg-latest.js

Lines changed: 20 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,6 @@ const defaultHTML =
2424
<script src="https://cdnjs.cloudflare.com/ajax/libs/p5.js/0.7.3/p5.min.js"></script>
2525
<script src="https://cdnjs.cloudflare.com/ajax/libs/p5.js/0.7.3/addons/p5.dom.min.js"></script>
2626
<script src="https://cdnjs.cloudflare.com/ajax/libs/p5.js/0.7.3/addons/p5.sound.min.js"></script>
27-
2827
<!-- Generative Design Dependencies here -->
2928
<!-- GG Bundled -->
3029
<script src="https://cdn.jsdelivr.net/gh/generative-design/Code-Package-p5.js@${branchName}/libraries/gg-dep-bundle/gg-dep-bundle.js"></script>
@@ -38,13 +37,10 @@ const defaultHTML =
3837
<script src="https://code.jquery.com/jquery-3.3.1.min.js"
3938
integrity="sha256-FgpCb/KJQlLNfOu91ta32o/NMZxltwRo8QtmkMRdAu8="
4039
crossorigin="anonymous"></script>
41-
4240
<!-- sketch additions -->
43-
4441
<link rel="stylesheet" type="text/css" href="style.css">
4542
</head>
4643
<body>
47-
4844
<!-- main -->
4945
<script src="sketch.js"></script>
5046
</body>
@@ -56,7 +52,6 @@ const defaultCSS =
5652
padding: 0;
5753
margin: 0;
5854
}
59-
6055
canvas {
6156
vertical-align: top;
6257
}
@@ -114,12 +109,11 @@ function getCodePackage() {
114109
// url: 'https://api.github.com/repos/generative-design/Code-Package-p5.js/contents',
115110
url: `https://api.github.com/repos/generative-design/Code-Package-p5.js/contents${branchRef}`,
116111
// url: 'https://api.github.com/repos/generative-design/Code-Package-p5.js/contents?ref=pre-release',
117-
qs: {
118-
client_id: clientId,
119-
client_secret: clientSecret
120-
},
121112
method: 'GET',
122-
headers,
113+
headers: {
114+
...headers,
115+
Authorization: `Basic ${Buffer.from(`${clientId}:${clientSecret}`).toString('base64')}`
116+
},
123117
json: true
124118
};
125119

@@ -144,12 +138,11 @@ function getSketchDirectories(sketchRootList) {
144138
// console.log(sketches)
145139
const options = {
146140
url: `https://api.github.com/repos/generative-design/Code-Package-p5.js/contents/${sketches.path}${branchRef}`,
147-
qs: {
148-
client_id: clientId,
149-
client_secret: clientSecret
150-
},
151141
method: 'GET',
152-
headers,
142+
headers: {
143+
...headers,
144+
Authorization: `Basic ${Buffer.from(`${clientId}:${clientSecret}`).toString('base64')}`
145+
},
153146
json: true
154147
};
155148

@@ -179,12 +172,11 @@ function appendSketchItemLinks(sketchList) {
179172
const options = {
180173
// url: `${sketches.url}?client_id=${clientId}&client_secret=${clientSecret}`,
181174
url: `https://api.github.com/repos/generative-design/Code-Package-p5.js/contents/${sketches.path}${branchRef}`,
182-
qs: {
183-
client_id: clientId,
184-
client_secret: clientSecret
185-
},
186175
method: 'GET',
187-
headers,
176+
headers: {
177+
...headers,
178+
Authorization: `Basic ${Buffer.from(`${clientId}:${clientSecret}`).toString('base64')}`
179+
},
188180
json: true
189181
};
190182

@@ -205,12 +197,11 @@ function getSketchItems(sketchList) {
205197
if (item.name === 'data') {
206198
const options = {
207199
url: `https://api.github.com/repos/generative-design/Code-Package-p5.js/contents/${item.path}${branchRef}`,
208-
qs: {
209-
client_id: clientId,
210-
client_secret: clientSecret
211-
},
212200
method: 'GET',
213-
headers,
201+
headers: {
202+
...headers,
203+
Authorization: `Basic ${Buffer.from(`${clientId}:${clientSecret}`).toString('base64')}`
204+
},
214205
json: true
215206
};
216207

@@ -409,12 +400,11 @@ function getAllSketchContent(newProjectList) {
409400
) {
410401
const options = {
411402
url: newProject.files[i].content,
412-
qs: {
413-
client_id: clientId,
414-
client_secret: clientSecret
415-
},
416403
method: 'GET',
417-
headers
404+
headers: {
405+
...headers,
406+
Authorization: `Basic ${Buffer.from(`${clientId}:${clientSecret}`).toString('base64')}`
407+
}
418408
};
419409

420410
// console.log("CONVERT ME!")

server/scripts/examples-ml5.js

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -25,12 +25,11 @@ ok(editorApiUrl, 'EDITOR_API_URL is required');
2525
//
2626
const githubRequestOptions = {
2727
url: baseUrl,
28-
qs: {
29-
client_id: clientId,
30-
client_secret: clientSecret
31-
},
3228
method: 'GET',
33-
headers,
29+
headers: {
30+
...headers,
31+
Authorization: `Basic ${Buffer.from(`${clientId}:${clientSecret}`).toString('base64')}`
32+
},
3433
json: true
3534
};
3635

server/scripts/examples.js

Lines changed: 20 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -49,10 +49,12 @@ mongoose.connection.on('error', () => {
4949
function getCategories() {
5050
const categories = [];
5151
const options = {
52-
url: `https://api.github.com/repos/processing/p5.js-website/contents/src/data/examples/en?client_id=${
53-
clientId}&client_secret=${clientSecret}`,
52+
url: 'https://api.github.com/repos/processing/p5.js-website/contents/src/data/examples/en',
5453
method: 'GET',
55-
headers,
54+
headers: {
55+
...headers,
56+
Authorization: `Basic ${Buffer.from(`${clientId}:${clientSecret}`).toString('base64')}`
57+
},
5658
json: true
5759
};
5860
return rp(options).then((res) => {
@@ -73,9 +75,12 @@ function getCategories() {
7375
function getSketchesInCategories(categories) {
7476
return Q.all(categories.map((category) => {
7577
const options = {
76-
url: `${category.url.replace('?ref=main', '')}?client_id=${clientId}&client_secret=${clientSecret}`,
78+
url: `${category.url.replace('?ref=main', '')}`,
7779
method: 'GET',
78-
headers,
80+
headers: {
81+
...headers,
82+
Authorization: `Basic ${Buffer.from(`${clientId}:${clientSecret}`).toString('base64')}`
83+
},
7984
json: true
8085
};
8186

@@ -107,9 +112,12 @@ function getSketchesInCategories(categories) {
107112
function getSketchContent(projectsInAllCategories) {
108113
return Q.all(projectsInAllCategories.map(projectsInOneCategory => Q.all(projectsInOneCategory.map((project) => {
109114
const options = {
110-
url: `${project.sketchUrl.replace('?ref=main', '')}?client_id=${clientId}&client_secret=${clientSecret}`,
115+
url: `${project.sketchUrl.replace('?ref=main', '')}`,
111116
method: 'GET',
112-
headers
117+
headers: {
118+
...headers,
119+
Authorization: `Basic ${Buffer.from(`${clientId}:${clientSecret}`).toString('base64')}`
120+
}
113121
};
114122

115123
return rp(options).then((res) => {
@@ -134,10 +142,12 @@ function getSketchContent(projectsInAllCategories) {
134142

135143
function createProjectsInP5user(projectsInAllCategories) {
136144
const options = {
137-
url: `https://api.github.com/repos/processing/p5.js-website/contents/src/data/examples/assets?client_id=${
138-
clientId}&client_secret=${clientSecret}`,
145+
url: 'https://api.github.com/repos/processing/p5.js-website/contents/src/data/examples/assets',
139146
method: 'GET',
140-
headers,
147+
headers: {
148+
...headers,
149+
Authorization: `Basic ${Buffer.from(`${clientId}:${clientSecret}`).toString('base64')}`
150+
},
141151
json: true
142152
};
143153

0 commit comments

Comments
 (0)