Skip to content

Commit

Permalink
Support local auth
Browse files Browse the repository at this point in the history
  • Loading branch information
riccardobl committed May 10, 2024
1 parent 4ab9224 commit 06c31e5
Showing 1 changed file with 21 additions and 1 deletion.
22 changes: 21 additions & 1 deletion src/auth/JsonAuth.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import Auth from "../Auth";
import {Event} from "nostr-tools";
import Logger from "../Logger";
import Fs from "fs";
type AuthCache = {
id: string;
methodName: string;
Expand All @@ -11,14 +12,33 @@ export default class JsonAuth extends Auth {
private baseUrl: string;
private authCache: AuthCache[] = [];
private poolPublicKey: string;
private authFile: string;

constructor(baseUrl: string, poolPublicKey: string) {
super();
this.baseUrl = baseUrl;
this.poolPublicKey = poolPublicKey;
}

async _getAuth(methodName: string, nodeId: string): Promise<AuthCache> {
async _getAuth(methodName: string, nodeId: string): Promise<boolean> {
if(!this.baseUrl.startsWith("http://")&&!this.baseUrl.startsWith("https://")){
this.logger.finer("Loading auth from file", this.baseUrl);
const data = await Fs.promises.readFile(this.baseUrl);
this.authFile=JSON.parse(data.toString());
const authorized =
this.authFile &&
this.authFile[nodeId] &&
this.authFile[nodeId][methodName] &&
this.authFile[nodeId][methodName] &&
this.authFile[nodeId][methodName]["authorized"]
? true
: false;


return authorized;
}


let auth = undefined;
for (let i = 0; i < this.authCache.length; i++) {
const cache = this.authCache[i];
Expand Down

0 comments on commit 06c31e5

Please sign in to comment.