mirror of
https://github.com/wkulhanek/bonob.git
synced 2025-12-21 17:33:29 +01:00
Auth tokens back to simple strings as private key used for token refresh which not doing
This commit is contained in:
@@ -1,6 +1,5 @@
|
|||||||
import axios from "axios";
|
import axios from "axios";
|
||||||
import { Md5 } from "ts-md5/dist/md5";
|
import { Md5 } from "ts-md5/dist/md5";
|
||||||
import { AuthToken } from "./link_codes";
|
|
||||||
|
|
||||||
const s = "foobar100";
|
const s = "foobar100";
|
||||||
const navidrome = process.env["BONOB_NAVIDROME_URL"];
|
const navidrome = process.env["BONOB_NAVIDROME_URL"];
|
||||||
@@ -14,7 +13,7 @@ export function isSuccess(authResult: AuthSuccess | AuthFailure): authResult is
|
|||||||
}
|
}
|
||||||
|
|
||||||
export type AuthSuccess = {
|
export type AuthSuccess = {
|
||||||
authToken: AuthToken
|
authToken: string
|
||||||
userId: string
|
userId: string
|
||||||
nickname: string
|
nickname: string
|
||||||
}
|
}
|
||||||
@@ -29,7 +28,7 @@ export interface MusicService {
|
|||||||
|
|
||||||
export class Navidrome implements MusicService {
|
export class Navidrome implements MusicService {
|
||||||
login({ username }: Credentials) {
|
login({ username }: Credentials) {
|
||||||
return { authToken: { value: `${username}`, version: "1" }, userId: username, nickname: username }
|
return { authToken: `v1:${username}`, userId: username, nickname: username }
|
||||||
}
|
}
|
||||||
|
|
||||||
ping = (): Promise<boolean> =>
|
ping = (): Promise<boolean> =>
|
||||||
|
|||||||
@@ -71,7 +71,7 @@ class SonosSoap {
|
|||||||
if (association) {
|
if (association) {
|
||||||
return {
|
return {
|
||||||
getDeviceAuthTokenResult: {
|
getDeviceAuthTokenResult: {
|
||||||
authToken: association.authToken.value,
|
authToken: association.authToken,
|
||||||
privateKey: "",
|
privateKey: "",
|
||||||
userInfo: {
|
userInfo: {
|
||||||
nickname: association.nickname,
|
nickname: association.nickname,
|
||||||
|
|||||||
@@ -15,7 +15,7 @@ export class InMemoryMusicService implements MusicService {
|
|||||||
password != undefined &&
|
password != undefined &&
|
||||||
this.users[username] == password
|
this.users[username] == password
|
||||||
) {
|
) {
|
||||||
return { authToken: { value: "token123", version: "1" }, userId: username, nickname: username };
|
return { authToken: "v1:token123", userId: username, nickname: username };
|
||||||
} else {
|
} else {
|
||||||
return { message: `Invalid user:${username}` };
|
return { message: `Invalid user:${username}` };
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -18,7 +18,7 @@ describe("InMemoryLinkCodes", () => {
|
|||||||
describe('when token is valid', () => {
|
describe('when token is valid', () => {
|
||||||
it('should associate the token', () => {
|
it('should associate the token', () => {
|
||||||
const linkCode = linkCodes.mint();
|
const linkCode = linkCodes.mint();
|
||||||
const association = { authToken: { value: "token123", version: "22" }, nickname: "bob", userId: "1" };
|
const association = { authToken: "token123", nickname: "bob", userId: "1" };
|
||||||
|
|
||||||
linkCodes.associate(linkCode, association);
|
linkCodes.associate(linkCode, association);
|
||||||
|
|
||||||
@@ -29,7 +29,7 @@ describe("InMemoryLinkCodes", () => {
|
|||||||
describe('when token is valid', () => {
|
describe('when token is valid', () => {
|
||||||
it('should throw an error', () => {
|
it('should throw an error', () => {
|
||||||
const invalidLinkCode = "invalidLinkCode";
|
const invalidLinkCode = "invalidLinkCode";
|
||||||
const association = { authToken: { value: "token123", version: "33" }, nickname: "bob", userId: "1" };
|
const association = { authToken: "token456", nickname: "bob", userId: "1" };
|
||||||
|
|
||||||
expect(() => linkCodes.associate(invalidLinkCode, association)).toThrow(`Invalid linkCode ${invalidLinkCode}`)
|
expect(() => linkCodes.associate(invalidLinkCode, association)).toThrow(`Invalid linkCode ${invalidLinkCode}`)
|
||||||
});
|
});
|
||||||
|
|||||||
@@ -175,7 +175,7 @@ describe("api", () => {
|
|||||||
describe("when there is a linkCode association", () => {
|
describe("when there is a linkCode association", () => {
|
||||||
it("should return a device auth token", async () => {
|
it("should return a device auth token", async () => {
|
||||||
const linkCode = linkCodes.mint();
|
const linkCode = linkCodes.mint();
|
||||||
const association = { authToken: { value: "at", version: "66" }, userId: "uid", nickname: "nn" };
|
const association = { authToken: "at", userId: "uid", nickname: "nn" };
|
||||||
linkCodes.associate(linkCode, association);
|
linkCodes.associate(linkCode, association);
|
||||||
|
|
||||||
const ws = await createClientAsync(`${service.uri}?wsdl`, {
|
const ws = await createClientAsync(`${service.uri}?wsdl`, {
|
||||||
@@ -187,8 +187,8 @@ describe("api", () => {
|
|||||||
|
|
||||||
expect(result[0]).toEqual({
|
expect(result[0]).toEqual({
|
||||||
getDeviceAuthTokenResult: {
|
getDeviceAuthTokenResult: {
|
||||||
authToken: association.authToken.value,
|
authToken: association.authToken,
|
||||||
privateKey: association.authToken.version,
|
privateKey: "",
|
||||||
userInfo: {
|
userInfo: {
|
||||||
nickname: association.nickname,
|
nickname: association.nickname,
|
||||||
userIdHashCode: crypto
|
userIdHashCode: crypto
|
||||||
|
|||||||
Reference in New Issue
Block a user