mirror of
https://github.com/wkulhanek/bonob.git
synced 2025-12-21 17:33:29 +01:00
Fix bug where authorisation token being truncated by sonos (#86)
This commit is contained in:
@@ -39,7 +39,6 @@ import { axiosImageFetcher, ImageFetcher } from "./subsonic";
|
||||
import {
|
||||
JWTSmapiLoginTokens,
|
||||
SmapiAuthTokens,
|
||||
smapiTokenFromString,
|
||||
} from "./smapi_auth";
|
||||
|
||||
export const BONOB_ACCESS_TOKEN_HEADER = "bat";
|
||||
@@ -378,28 +377,23 @@ function server(
|
||||
logger.info(
|
||||
`${trace} bnb<- ${req.method} ${req.path}?${JSON.stringify(
|
||||
req.query
|
||||
)}, headers=${JSON.stringify({ ...req.headers, authorization: "*****" })}`
|
||||
)}, headers=${JSON.stringify({ ...req.headers, "bnbt": "*****", "bnbk": "*****" })}`
|
||||
);
|
||||
|
||||
const authHeader = E.fromNullable("Missing header");
|
||||
const bearerToken = E.fromNullable("No Bearer token");
|
||||
const serviceToken = pipe(
|
||||
authHeader(req.headers["authorization"] as string),
|
||||
E.chain((authorization) =>
|
||||
E.fromNullable("Missing bnbt header")(req.headers["bnbt"] as string),
|
||||
E.chain(token => pipe(
|
||||
E.fromNullable("Missing bnbk header")(req.headers["bnbk"] as string),
|
||||
E.map(key => ({ token, key }))
|
||||
)),
|
||||
E.chain((auth) =>
|
||||
pipe(
|
||||
authorization.match(/Bearer (?<token>.*)/),
|
||||
bearerToken,
|
||||
E.map((match) => match[1]!)
|
||||
)
|
||||
),
|
||||
E.chain((bearerToken) =>
|
||||
pipe(
|
||||
smapiAuthTokens.verify(smapiTokenFromString(bearerToken)),
|
||||
E.mapLeft((_) => "Bearer token failed to verify")
|
||||
smapiAuthTokens.verify(auth),
|
||||
E.mapLeft((_) => "Auth token failed to verify")
|
||||
)
|
||||
),
|
||||
E.getOrElseW(() => undefined)
|
||||
);
|
||||
)
|
||||
|
||||
if (!serviceToken) {
|
||||
return res.status(401).send();
|
||||
|
||||
13
src/smapi.ts
13
src/smapi.ts
@@ -32,7 +32,6 @@ import {
|
||||
isExpiredTokenError,
|
||||
MissingLoginTokenError,
|
||||
SmapiAuthTokens,
|
||||
smapiTokenAsString,
|
||||
SMAPI_FAULT_LOGIN_UNAUTHORIZED,
|
||||
ToSmapiFault,
|
||||
} from "./smapi_auth";
|
||||
@@ -532,10 +531,14 @@ function bindSmapiSoapServiceToExpress(
|
||||
httpHeaders: [
|
||||
{
|
||||
httpHeader: {
|
||||
header: "Authorization",
|
||||
value: `Bearer ${smapiTokenAsString(
|
||||
credentials.loginToken
|
||||
)}`,
|
||||
header: "bnbt",
|
||||
value: credentials.loginToken.token,
|
||||
},
|
||||
},
|
||||
{
|
||||
httpHeader: {
|
||||
header: "bnbk",
|
||||
value: credentials.loginToken.key,
|
||||
},
|
||||
},
|
||||
],
|
||||
|
||||
Reference in New Issue
Block a user