mirror of
https://github.com/wkulhanek/bonob.git
synced 2025-12-21 17:33:29 +01:00
More edits
This commit is contained in:
13
src/smapi.ts
13
src/smapi.ts
@@ -415,8 +415,13 @@ function bindSmapiSoapServiceToExpress(
|
|||||||
const credentialsFrom = E.fromNullable(new MissingLoginTokenError());
|
const credentialsFrom = E.fromNullable(new MissingLoginTokenError());
|
||||||
return pipe(
|
return pipe(
|
||||||
credentialsFrom(credentials),
|
credentialsFrom(credentials),
|
||||||
E.chain((credentials) =>
|
E.chain((credentials) => {
|
||||||
pipe(
|
// Check if token/key is associated with a user
|
||||||
|
const smapiToken = sonosSoap.getCredentialsForToken(credentials.loginToken.token);
|
||||||
|
if (!smapiToken || smapiToken.key !== credentials.loginToken.key) {
|
||||||
|
return E.left(new InvalidTokenError("Token not associated with any user"));
|
||||||
|
}
|
||||||
|
return pipe(
|
||||||
smapiAuthTokens.verify({
|
smapiAuthTokens.verify({
|
||||||
token: credentials.loginToken.token,
|
token: credentials.loginToken.token,
|
||||||
key: credentials.loginToken.key,
|
key: credentials.loginToken.key,
|
||||||
@@ -425,8 +430,8 @@ function bindSmapiSoapServiceToExpress(
|
|||||||
serviceToken,
|
serviceToken,
|
||||||
credentials,
|
credentials,
|
||||||
}))
|
}))
|
||||||
)
|
);
|
||||||
),
|
}),
|
||||||
E.map(({ serviceToken, credentials }) => ({
|
E.map(({ serviceToken, credentials }) => ({
|
||||||
serviceToken,
|
serviceToken,
|
||||||
credentials,
|
credentials,
|
||||||
|
|||||||
@@ -4,6 +4,8 @@ import { v4 as uuid } from "uuid";
|
|||||||
import { b64Decode, b64Encode } from "./b64";
|
import { b64Decode, b64Encode } from "./b64";
|
||||||
import { Clock } from "./clock";
|
import { Clock } from "./clock";
|
||||||
|
|
||||||
|
import logger from "./logger";
|
||||||
|
|
||||||
export type SmapiFault = { Fault: { faultcode: string; faultstring: string } };
|
export type SmapiFault = { Fault: { faultcode: string; faultstring: string } };
|
||||||
export type SmapiRefreshTokenResultFault = SmapiFault & {
|
export type SmapiRefreshTokenResultFault = SmapiFault & {
|
||||||
Fault: {
|
Fault: {
|
||||||
@@ -14,6 +16,7 @@ export type SmapiRefreshTokenResultFault = SmapiFault & {
|
|||||||
};
|
};
|
||||||
|
|
||||||
function isError(thing: any): thing is Error {
|
function isError(thing: any): thing is Error {
|
||||||
|
logger.debug("isError check", { thing });
|
||||||
return thing.name && thing.message;
|
return thing.name && thing.message;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user