Skip to content

Commit

Permalink
Merge pull request #3239 from getAlby/add-identifier-for-oauth
Browse files Browse the repository at this point in the history
feat: add identifier in auth url
  • Loading branch information
pavanjoshi914 committed Sep 8, 2024
2 parents da4e255 + e301dc0 commit 317ea43
Showing 1 changed file with 29 additions and 0 deletions.
29 changes: 29 additions & 0 deletions src/extension/background-script/connectors/alby.ts
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ interface Config {
password: string;
url: string;
oAuthToken: OAuthToken | undefined;
userIdentifer: string | undefined;
}

export default class Alby implements Connector {
Expand Down Expand Up @@ -64,6 +65,25 @@ export default class Alby implements Connector {
return this.config.oAuthToken;
}

async persistUserIdentifier(userIdentifier: string): Promise<void> {
if (!this.config.userIdentifer) {
if (this.account.id) {
const accounts = state.getState().accounts;
const password = (await state.getState().password()) as string;

const configData = decryptData(
accounts[this.account.id].config,
password
);
configData.userIdentifer = userIdentifier;
accounts[this.account.id].config = encryptData(configData, password);
state.setState({ accounts });
// make sure we immediately persist the updated accounts
await state.getState().saveToStorage();
}
}
}

unload() {
return Promise.resolve();
}
Expand Down Expand Up @@ -123,6 +143,9 @@ export default class Alby implements Connector {
>;

if (cacheValue) {
if (!this.config.userIdentifer) {
this.persistUserIdentifier(cacheValue.data.identifier);
}
return cacheValue;
}

Expand All @@ -137,6 +160,9 @@ export default class Alby implements Connector {
};
this._cache.set(cacheKey, returnValue);

if (!this.config.userIdentifer) {
this.persistUserIdentifier(info.identifier);
}
return returnValue;
} catch (error) {
console.error(error);
Expand Down Expand Up @@ -295,6 +321,9 @@ export default class Alby implements Connector {
});

authUrl += "&webln=false"; // stop getalby.com login modal launching lnurl auth
if (this.config.userIdentifer) {
authUrl += `&identifier=${this.config.userIdentifer}`;
}

const oAuthTab = await browser.tabs.create({ url: authUrl });

Expand Down

0 comments on commit 317ea43

Please sign in to comment.