core: support custom and relative path redirect uri for oauth clients

This commit is contained in:
Koushik Dutta
2022-08-29 11:22:29 -07:00
parent 3af43635f2
commit 9f57969690
3 changed files with 24 additions and 6 deletions

View File

@@ -1,12 +1,12 @@
{
"name": "@scrypted/core",
"version": "0.1.27",
"version": "0.1.28",
"lockfileVersion": 2,
"requires": true,
"packages": {
"": {
"name": "@scrypted/core",
"version": "0.1.27",
"version": "0.1.28",
"license": "Apache-2.0",
"dependencies": {
"@scrypted/common": "file:../../common",

View File

@@ -1,6 +1,6 @@
{
"name": "@scrypted/core",
"version": "0.1.27",
"version": "0.1.28",
"description": "Scrypted Core plugin. Provides the UI, websocket, and engine.io APIs.",
"author": "Scrypted",
"license": "Apache-2.0",

View File

@@ -8,14 +8,32 @@ import qs from 'query-string';
export default {
mixins: [RPCInterface],
methods: {
onChange() {},
onClick: function() {
onChange() { },
onClick: function () {
this.rpc()
.getOauthUrl()
.then(data => {
var url = new URL(data);
var querystring = qs.parse(url.search.replace("?", ""));
querystring.redirect_uri = `https://home.scrypted.app/web/oauth/callback`;
let { redirect_uri } = querystring;
if (redirect_uri) {
let u;
try {
u = new URL(redirect_uri);
}
catch (e) {
u = new URL(redirect_uri, window.location.href);
u.hostname = 'localhost';
}
if (u.hostname === 'localhost') {
u.hostname = new URL(window.location.href).hostname;
redirect_uri = u.toString();
}
}
else {
redirect_uri = `https://home.scrypted.app/web/oauth/callback`;
}
querystring.redirect_uri = redirect_uri;
querystring.state = JSON.stringify({
d: this.device.id,
s: querystring.state,