Started adding Github Oauth2 system for creators
This commit is contained in:
@@ -18,6 +18,7 @@ const SetAuthentication = (props) => {
|
|||||||
//session_state
|
//session_state
|
||||||
const urlSearchParams = new URLSearchParams(window.location.search);
|
const urlSearchParams = new URLSearchParams(window.location.search);
|
||||||
const params = Object.fromEntries(urlSearchParams.entries());
|
const params = Object.fromEntries(urlSearchParams.entries());
|
||||||
|
console.log("PARAMS: ", params)
|
||||||
|
|
||||||
const authenticationStore = [];
|
const authenticationStore = [];
|
||||||
var appAuthData = {
|
var appAuthData = {
|
||||||
@@ -29,19 +30,16 @@ const SetAuthentication = (props) => {
|
|||||||
},
|
},
|
||||||
fields: [],
|
fields: [],
|
||||||
type: "oauth2",
|
type: "oauth2",
|
||||||
};
|
}
|
||||||
|
|
||||||
if (window !== undefined && window !== null) {
|
if (window !== undefined && window !== null) {
|
||||||
console.log(window.location);
|
//console.log(window.location);
|
||||||
appAuthData.fields.push({
|
appAuthData.fields.push({
|
||||||
key: "redirect_uri",
|
key: "redirect_uri",
|
||||||
value: window.location.origin + window.location.pathname,
|
value: window.location.origin + window.location.pathname,
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
if (params.code !== undefined && params.code !== null) {
|
|
||||||
appAuthData.fields.push({ key: "code", value: params.code });
|
|
||||||
}
|
|
||||||
|
|
||||||
if (params.session_state !== undefined && params.session_state !== null) {
|
if (params.session_state !== undefined && params.session_state !== null) {
|
||||||
appAuthData.fields.push({
|
appAuthData.fields.push({
|
||||||
@@ -50,12 +48,34 @@ const SetAuthentication = (props) => {
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
var externalData = {
|
||||||
|
handleExternal: false,
|
||||||
|
user: "",
|
||||||
|
type: "",
|
||||||
|
code: "",
|
||||||
|
}
|
||||||
|
|
||||||
|
if (params.code !== undefined && params.code !== null) {
|
||||||
|
appAuthData.fields.push({ key: "code", value: params.code });
|
||||||
|
externalData.code = params.code
|
||||||
|
}
|
||||||
|
|
||||||
if (params.state !== undefined && params.state !== null) {
|
if (params.state !== undefined && params.state !== null) {
|
||||||
const paramsplit = params.state.split("&");
|
const paramsplit = params.state.split("&");
|
||||||
console.log(paramsplit);
|
console.log(paramsplit);
|
||||||
for (var key in paramsplit) {
|
for (var key in paramsplit) {
|
||||||
const query = paramsplit[key].split("=");
|
const query = paramsplit[key].split("=");
|
||||||
console.log(query);
|
console.log("K:V: ", key, query);
|
||||||
|
if (query.length > 1) {
|
||||||
|
if (query[0] === "type" && query[1] === "github"){
|
||||||
|
externalData.handleExternal = true
|
||||||
|
externalData.type = "github"
|
||||||
|
}
|
||||||
|
|
||||||
|
if (query[0] === "username" || query[0] === "user"){
|
||||||
|
externalData.user = query[1]
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
if (query.length !== 2) {
|
if (query.length !== 2) {
|
||||||
console.log("INVALID QUERY: ", query);
|
console.log("INVALID QUERY: ", query);
|
||||||
@@ -116,6 +136,78 @@ const SetAuthentication = (props) => {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (externalData.handleExternal) {
|
||||||
|
console.log("RUN EXTERNAL!!: ", externalData)
|
||||||
|
|
||||||
|
fetch(globalUrl + "/api/v1/triggers/github/register", {
|
||||||
|
method: "PUT",
|
||||||
|
headers: {
|
||||||
|
"Content-Type": "application/json",
|
||||||
|
Accept: "application/json",
|
||||||
|
},
|
||||||
|
credentials: "include",
|
||||||
|
body: JSON.stringify(externalData),
|
||||||
|
})
|
||||||
|
.then((response) => {
|
||||||
|
const cursearch = typeof window === "undefined" || window.location === undefined ? "" : window.location.search;
|
||||||
|
const tmpView = new URLSearchParams(cursearch).get("state");
|
||||||
|
if (
|
||||||
|
tmpView !== undefined &&
|
||||||
|
tmpView !== null &&
|
||||||
|
tmpView.length > 0
|
||||||
|
) {
|
||||||
|
console.log("State to find app name from: ", tmpView)
|
||||||
|
}
|
||||||
|
|
||||||
|
if (response.status !== 200) {
|
||||||
|
console.log("Status not 200 for oauth2 authentication");
|
||||||
|
setFailed(true);
|
||||||
|
} else {
|
||||||
|
setFinished(true);
|
||||||
|
//setTimeout(() => {
|
||||||
|
// window.close();
|
||||||
|
//}, 2500);
|
||||||
|
}
|
||||||
|
|
||||||
|
return response.json();
|
||||||
|
})
|
||||||
|
.then((responseJson) => {
|
||||||
|
//setUserSettings(responseJson)
|
||||||
|
console.log("Resp: ", responseJson);
|
||||||
|
|
||||||
|
if (responseJson.reason !== undefined) {
|
||||||
|
setResponse(responseJson.reason);
|
||||||
|
setFinished(true);
|
||||||
|
|
||||||
|
} else {
|
||||||
|
const cursearch = typeof window === "undefined" || window.location === undefined ? "" : window.location.search;
|
||||||
|
var tmpView = new URLSearchParams(cursearch).get("error_description");
|
||||||
|
if (
|
||||||
|
tmpView !== undefined &&
|
||||||
|
tmpView !== null &&
|
||||||
|
tmpView.length > 0
|
||||||
|
) {
|
||||||
|
setResponse(tmpView)
|
||||||
|
} else {
|
||||||
|
tmpView = new URLSearchParams(cursearch).get("error");
|
||||||
|
if (
|
||||||
|
tmpView !== undefined &&
|
||||||
|
tmpView !== null &&
|
||||||
|
tmpView.length > 0
|
||||||
|
) {
|
||||||
|
setResponse(tmpView)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
})
|
||||||
|
.catch((error) => {
|
||||||
|
console.log(error);
|
||||||
|
});
|
||||||
|
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
console.log(appAuthData);
|
console.log(appAuthData);
|
||||||
|
|
||||||
fetch(globalUrl + "/api/v1/apps/authentication", {
|
fetch(globalUrl + "/api/v1/apps/authentication", {
|
||||||
|
|||||||
@@ -728,17 +728,19 @@ const Settings = (props) => {
|
|||||||
<h2>Platform Earnings</h2>
|
<h2>Platform Earnings</h2>
|
||||||
<div style={{ display: runFlex ? "flex" : "", width: "100%" }}>
|
<div style={{ display: runFlex ? "flex" : "", width: "100%" }}>
|
||||||
<div>
|
<div>
|
||||||
|
{isCloud ?
|
||||||
<Button
|
<Button
|
||||||
style={{ height: 40, marginTop: 10 }}
|
style={{ height: 40, marginTop: 10 }}
|
||||||
variant="outlined"
|
variant="outlined"
|
||||||
color="primary"
|
color="primary"
|
||||||
fullWidth={true}
|
fullWidth={true}
|
||||||
onClick={() => {
|
onClick={() => {
|
||||||
handleEthereumConnection();
|
handleGithubConnection();
|
||||||
}}
|
}}
|
||||||
>
|
>
|
||||||
Connect to Github
|
Connect to Github
|
||||||
</Button>
|
</Button>
|
||||||
|
: null}
|
||||||
</div>
|
</div>
|
||||||
<div style={{ flex: 1, display: "flex" }}>
|
<div style={{ flex: 1, display: "flex" }}>
|
||||||
<div>
|
<div>
|
||||||
@@ -914,6 +916,64 @@ const Settings = (props) => {
|
|||||||
});
|
});
|
||||||
};
|
};
|
||||||
|
|
||||||
|
const handleGithubConnection = () => {
|
||||||
|
console.log("GITHUB CONNECT WOO")
|
||||||
|
//result = RestClient.post('https://github.com/login/oauth/access_token',
|
||||||
|
|
||||||
|
console.log("HOST: ", window.location.host);
|
||||||
|
console.log("HOST: ", window.location);
|
||||||
|
const redirectUri = isCloud
|
||||||
|
? window.location.host === "localhost:3002"
|
||||||
|
? "http%3A%2F%2Flocalhost:3002%2Fset_authentication"
|
||||||
|
: "https%3A%2F%2Fshuffler.io%2Fset_authentication"
|
||||||
|
: window.location.protocol === "http:" ?
|
||||||
|
`http%3A%2F%2F${window.location.host}%2Fset_authentication`
|
||||||
|
:
|
||||||
|
`https%3A%2F%2F${window.location.host}%2Fset_authentication`
|
||||||
|
|
||||||
|
|
||||||
|
const client_id = "3d272b1b782b100b1e61"
|
||||||
|
const username = userdata.id;
|
||||||
|
const scopes = "user:email";
|
||||||
|
|
||||||
|
const url = `https://github.com/login/oauth/authorize?access_type=offline&prompt=consent&client_id=${client_id}&redirect_uri=${redirectUri}&response_type=code&scope=${scopes}&state=username%3D${username}%26type%3Dgithub`
|
||||||
|
|
||||||
|
console.log("URL: ", url);
|
||||||
|
|
||||||
|
var newwin = window.open(url, "", "width=800,height=600");
|
||||||
|
|
||||||
|
// Check whether we got a callback somewhere
|
||||||
|
//var id = setInterval(function () {
|
||||||
|
// fetch(
|
||||||
|
// globalUrl + "/api/v1/triggers/gmail/" + selectedTrigger.id,
|
||||||
|
// {
|
||||||
|
// method: "GET",
|
||||||
|
// headers: { "content-type": "application/json" },
|
||||||
|
// credentials: "include",
|
||||||
|
// }
|
||||||
|
// )
|
||||||
|
// .then((response) => {
|
||||||
|
// if (response.status !== 200) {
|
||||||
|
// throw new Error("No trigger info :o!");
|
||||||
|
// }
|
||||||
|
|
||||||
|
// return response.json();
|
||||||
|
// })
|
||||||
|
// .then((responseJson) => {
|
||||||
|
// console.log("RESPONSE: ");
|
||||||
|
// setTriggerAuthentication(responseJson);
|
||||||
|
// clearInterval(id);
|
||||||
|
// newwin.close();
|
||||||
|
// setGmailFolders();
|
||||||
|
// })
|
||||||
|
// .catch((error) => {
|
||||||
|
// console.log(error.toString());
|
||||||
|
// });
|
||||||
|
//}, 2500);
|
||||||
|
|
||||||
|
//saveWorkflow(workflow);
|
||||||
|
}
|
||||||
|
|
||||||
const handleEthereumTokenCreation = async () => {
|
const handleEthereumTokenCreation = async () => {
|
||||||
const provider = await detectEthereumProvider();
|
const provider = await detectEthereumProvider();
|
||||||
if (!provider) {
|
if (!provider) {
|
||||||
|
|||||||
Reference in New Issue
Block a user