mirror of
https://github.com/wkulhanek/bonob.git
synced 2025-12-22 01:43:29 +01:00
Non expiring access token per auth token
This commit is contained in:
@@ -76,3 +76,21 @@ export class EncryptedAccessTokens implements AccessTokens {
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
export class AccessTokenPerAuthToken implements AccessTokens {
|
||||
authTokenToAccessToken = new Map<string, string>();
|
||||
accessTokenToAuthToken = new Map<string, string>();
|
||||
|
||||
mint = (authToken: string): string => {
|
||||
if (this.authTokenToAccessToken.has(authToken)) {
|
||||
return this.authTokenToAccessToken.get(authToken)!;
|
||||
} else {
|
||||
const accessToken = uuid();
|
||||
this.authTokenToAccessToken.set(authToken, accessToken);
|
||||
this.accessTokenToAuthToken.set(accessToken, authToken);
|
||||
return accessToken;
|
||||
}
|
||||
};
|
||||
|
||||
authTokenFor = (value: string): string | undefined => this.accessTokenToAuthToken.get(value);
|
||||
}
|
||||
|
||||
@@ -13,9 +13,7 @@ import {
|
||||
import { LinkCodes, InMemoryLinkCodes } from "./link_codes";
|
||||
import { MusicService, isSuccess } from "./music_service";
|
||||
import bindSmapiSoapServiceToExpress from "./smapi";
|
||||
import { AccessTokens, EncryptedAccessTokens } from "./access_tokens";
|
||||
import encryption from "./encryption";
|
||||
import randomString from "./random_string";
|
||||
import { AccessTokens, AccessTokenPerAuthToken } from "./access_tokens";
|
||||
|
||||
export const BONOB_ACCESS_TOKEN_HEADER = "bonob-access-token";
|
||||
|
||||
@@ -25,9 +23,7 @@ function server(
|
||||
webAddress: string | "http://localhost:4534",
|
||||
musicService: MusicService,
|
||||
linkCodes: LinkCodes = new InMemoryLinkCodes(),
|
||||
accessTokens: AccessTokens = new EncryptedAccessTokens(
|
||||
encryption(randomString())
|
||||
)
|
||||
accessTokens: AccessTokens = new AccessTokenPerAuthToken()
|
||||
): Express {
|
||||
const app = express();
|
||||
|
||||
|
||||
Reference in New Issue
Block a user