@iobroker/json-config 8.2.14 → 8.2.15

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/README.md CHANGED
@@ -1749,7 +1749,7 @@ The schema is used here: https://github.com/SchemaStore/schemastore/blob/6da29cd
1749
1749
  ### **WORK IN PROGRESS**
1750
1750
  -->
1751
1751
  ## Changelog
1752
- ### 8.2.14 (2026-03-24)
1752
+ ### 8.2.15 (2026-03-24)
1753
1753
  - (@GermanBluefox) Added the possibility to use own Client ID for oauth authentication
1754
1754
 
1755
1755
  ### 8.2.11 (2026-03-20)
@@ -88,7 +88,7 @@ export default class ConfigOAuth2 extends ConfigGeneric {
88
88
  // Give 10 seconds to user to copy the token
89
89
  accessTokensParsed.access_token_expires_on ||= new Date(Date.now() + accessTokensParsed.expires_in * 1000).toISOString();
90
90
  if (this.props.schema.ownClientId) {
91
- accessTokensParsed.client_id = ConfigGeneric.getValue(this.props.data, this.props.schema.ownClientSecret);
91
+ accessTokensParsed.client_id = ConfigGeneric.getValue(this.props.data, this.props.schema.ownClientId);
92
92
  }
93
93
  this.props.oContext.socket
94
94
  .setState(this.oid, JSON.stringify(accessTokensParsed), true)
@@ -156,7 +156,7 @@ export default class ConfigOAuth2 extends ConfigGeneric {
156
156
  this.props.schema.ownClientId ? (React.createElement(TextField, { value: this.state.clientId, onChange: e => {
157
157
  const value = e.target.value;
158
158
  this.setState({ clientId: value }, () => this.onChange(this.props.schema.ownClientId, value));
159
- }, variant: "standard", fullWidth: true, error: !this.state.clientId, disabled: !!disabled, label: I18n.t('ra_OAuth Client ID'), slotProps: {
159
+ }, style: { marginBottom: 8 }, variant: "standard", fullWidth: true, error: !this.state.clientId, disabled: !!disabled, label: I18n.t('ra_OAuth Client ID'), slotProps: {
160
160
  input: {
161
161
  endAdornment: this.state.clientId ? (React.createElement(IconButton, { size: "small", tabIndex: -1, onClick: () => this.setState({ clientId: '' }, () => this.onChange(this.props.schema.ownClientId, '')) },
162
162
  React.createElement(CloseIcon, null))) : null,
@@ -165,7 +165,7 @@ export default class ConfigOAuth2 extends ConfigGeneric {
165
165
  this.props.schema.ownClientSecret ? (React.createElement(TextField, { value: this.state.clientSecret, onChange: e => {
166
166
  const value = e.target.value;
167
167
  this.setState({ clientSecret: value }, () => this.onChange(this.props.schema.ownClientSecret, value));
168
- }, variant: "standard", fullWidth: true, error: !this.state.clientSecret, disabled: !!disabled, label: I18n.t('ra_OAuth Client secret'), slotProps: {
168
+ }, style: { marginBottom: 8 }, variant: "standard", fullWidth: true, error: !this.state.clientSecret, disabled: !!disabled, label: I18n.t('ra_OAuth Client secret'), slotProps: {
169
169
  input: {
170
170
  endAdornment: this.state.clientSecret ? (React.createElement(IconButton, { size: "small", tabIndex: -1, onClick: () => this.setState({ clientSecret: '' }, () => this.onChange(this.props.schema.ownClientSecret, '')) },
171
171
  React.createElement(CloseIcon, null))) : null,
@@ -1 +1 @@
1
- {"version":3,"file":"ConfigOAuth2.js","sourceRoot":"./src/","sources":["JsonConfigComponent/ConfigOAuth2.tsx"],"names":[],"mappings":"AAAA,OAAO,KAAK,MAAM,OAAO,CAAC;AAE1B,OAAO,EAAE,MAAM,EAAE,UAAU,EAAE,SAAS,EAAE,MAAM,eAAe,CAAC;AAC9D,OAAO,EAAE,KAAK,IAAI,SAAS,EAAE,WAAW,EAAE,MAAM,qBAAqB,CAAC;AAEtE,OAAO,EAAE,IAAI,EAAE,MAAM,4BAA4B,CAAC;AAElD,OAAO,aAAmE,MAAM,iBAAiB,CAAC;AAmClG,MAAM,CAAC,OAAO,OAAO,YAAa,SAAQ,aAAmD;IACjF,UAAU,CAAsB;IACvB,GAAG,CAAS;IACZ,GAAG,CAAS;IAE7B,YAAY,KAAwB;QAChC,KAAK,CAAC,KAAK,CAAC,CAAC;QAEb,IAAI,CAAC,KAAK,GAAG;YACT,GAAG,IAAI,CAAC,KAAK;YACb,YAAY,EAAE,EAAE;YAChB,OAAO,EAAE,KAAK;YACd,OAAO,EA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from '@mui/material';\nimport { Close as CloseIcon, CloudUpload } from '@mui/icons-material';\n\nimport { I18n } from '@iobroker/adapter-react-v5';\n\nimport ConfigGeneric, { type ConfigGenericProps, type ConfigGenericState } from './ConfigGeneric';\nimport type { ConfigItemOAuth2 } from '../types';\n\ndeclare global {\n interface Window {\n attachEvent: Window['addEventListener'];\n detachEvent: Window['removeEventListener'];\n }\n}\n\ninterface ConfigOAuth2Props extends ConfigGenericProps {\n schema: ConfigItemOAuth2;\n}\n\nexport interface AccessTokens {\n access_token: string;\n expires_in: number;\n access_token_expires_on: string;\n ext_expires_in: number;\n token_type: 'Bearer';\n scope: string;\n refresh_token: string;\n client_id: string;\n}\n\ninterface ConfigOAuth2State extends ConfigGenericState {\n accessTokens: string;\n success: boolean;\n blocked: boolean;\n running: boolean;\n pressed: boolean;\n clientId: string;\n clientSecret: string;\n}\n\nexport default class ConfigOAuth2 extends ConfigGeneric<ConfigOAuth2Props, ConfigOAuth2State> {\n private authWindow?: WindowProxy | null;\n private readonly oid: string;\n private readonly url: string;\n\n constructor(props: ConfigOAuth2Props) {\n super(props);\n\n this.state = {\n ...this.state,\n accessTokens: '',\n success: false,\n blocked: false,\n running: false,\n pressed: false,\n clientId: '',\n clientSecret: '',\n };\n\n this.url = `https://oauth2.iobroker.in/${props.schema.identifier}?redirect=true`;\n if (props.schema.scope) {\n this.url += `&scope=${encodeURIComponent(props.schema.scope)}`;\n }\n\n this.oid = `${this.props.oContext.adapterName}.${this.props.oContext.instance}.${this.props.schema.saveTokenIn || 'oauth2Tokens'}`;\n }\n\n async componentDidMount(): Promise<void> {\n super.componentDidMount();\n if (window.addEventListener) {\n window.addEventListener('message', this.onMessage as any, false);\n } else {\n window.attachEvent('onmessage', this.onMessage as any, false);\n }\n\n await this.props.oContext.socket.subscribeState(this.oid, this.onTokensUpdated);\n\n let state: Partial<ConfigOAuth2State> | undefined;\n if (this.props.schema.ownClientId) {\n state = { clientId: ConfigGeneric.getValue(this.props.data, this.props.schema.ownClientId) };\n }\n if (this.props.schema.ownClientId) {\n state ||= {};\n state.clientSecret = ConfigGeneric.getValue(this.props.data, this.props.schema.ownClientSecret);\n }\n\n // read tokens\n const tokens = await this.props.oContext.socket.getState(this.oid);\n if (tokens) {\n const accessTokens: AccessTokens = JSON.parse(tokens.val as string);\n if (new Date(accessTokens.access_token_expires_on).getTime() > Date.now()) {\n state ||= {};\n state.accessTokens = tokens.val as string;\n }\n }\n if (state) {\n this.setState(state as ConfigOAuth2State);\n }\n }\n\n onTokensUpdated = (_id: string, state: ioBroker.State | null | undefined): void => {\n if (state?.val) {\n const accessTokens: AccessTokens = JSON.parse(state.val as string);\n if (new Date(accessTokens.access_token_expires_on).getTime() > Date.now()) {\n if (this.state.accessTokens !== state.val) {\n this.setState({ accessTokens: state.val as string });\n }\n return;\n }\n }\n this.setState({ accessTokens: '' });\n };\n\n componentWillUnmount(): void {\n super.componentWillUnmount();\n if (window.removeEventListener) {\n window.removeEventListener('message', this.onMessage as any, false);\n } else {\n window.detachEvent('onmessage', this.onMessage as any, false);\n }\n this.props.oContext.socket.unsubscribeState(this.oid, this.onTokensUpdated);\n }\n\n saveToken(accessTokens: string): void {\n try {\n if (accessTokens && !accessTokens.startsWith('{')) {\n // convert base64 to string\n accessTokens = atob(accessTokens);\n }\n\n const accessTokensParsed: AccessTokens = JSON.parse(accessTokens);\n if (accessTokensParsed.access_token && accessTokensParsed.refresh_token && accessTokensParsed.expires_in) {\n // Give 10 seconds to user to copy the token\n accessTokensParsed.access_token_expires_on ||= new Date(\n Date.now() + accessTokensParsed.expires_in * 1000,\n ).toISOString();\n if (this.props.schema.ownClientId) {\n accessTokensParsed.client_id = ConfigGeneric.getValue(\n this.props.data,\n this.props.schema.ownClientSecret,\n );\n }\n\n this.props.oContext.socket\n .setState(this.oid, JSON.stringify(accessTokensParsed), true)\n .catch((e: Error) => console.log(`Error occurred: ${e.toString()}`));\n }\n } catch (e) {\n // ignore\n console.warn(e);\n }\n }\n\n onMessage = (event: MessageEvent): void => {\n if (event.origin !== 'https://oauth2.iobroker.in') {\n return;\n }\n if (\n (typeof event.data === 'string' &&\n event.data.startsWith(`${this.props.schema.identifier}-authentication:`)) ||\n (typeof (event as any).message === 'string' &&\n (event as any).message.startsWith(`${this.props.schema.identifier}-authentication:`))\n ) {\n const parts = (event.data || (event as any).message).split(':');\n if (parts[1] === 'success') {\n this.setState({ accessTokens: parts[2], success: true, pressed: false }, () =>\n this.saveToken(this.state.accessTokens),\n );\n\n // send message to auth window to close it\n this.authWindow?.postMessage('close', event.origin);\n this.authWindow = null;\n } else {\n this.props.onError?.(parts[2]);\n }\n }\n };\n\n onOpenUrl(): void {\n this.authWindow = window.open(\n this.url + (this.props.schema.ownClientId ? `&clientId=${encodeURIComponent(this.state.clientId)}` : ''),\n this.props.schema.identifier,\n );\n if (!this.authWindow || this.authWindow.closed || typeof this.authWindow.closed === 'undefined') {\n this.setState({ blocked: true });\n } else {\n this.setState({ pressed: true });\n }\n }\n\n renderItem(_error?: boolean, disabled?: boolean): React.JSX.Element {\n let validTill = '';\n if (this.state.accessTokens) {\n try {\n const accessTokensParsed: AccessTokens = JSON.parse(this.state.accessTokens);\n validTill = new Date(accessTokensParsed.access_token_expires_on).toLocaleString();\n } catch {\n // ignore\n }\n }\n\n let label: string;\n if (this.state.accessTokens) {\n label = this.props.schema.refreshLabel\n ? this.getText(this.props.schema.refreshLabel)\n : I18n.t(\n 'ra_Renew %s access',\n this.props.schema.identifier[0].toUpperCase() + this.props.schema.identifier.slice(1),\n );\n } else {\n label = this.props.schema.label\n ? this.getText(this.props.schema.label)\n : I18n.t(\n 'ra_Get %s access',\n this.props.schema.identifier[0].toUpperCase() + this.props.schema.identifier.slice(1),\n );\n }\n const icon = this.getIcon();\n\n return (\n <div style={{ width: '100%', margin: '0 0 1rem 0' }}>\n {this.props.schema.ownClientId ? (\n <TextField\n value={this.state.clientId}\n onChange={e => {\n const value = e.target.value;\n\n this.setState({ clientId: value }, () =>\n this.onChange(this.props.schema.ownClientId, value),\n );\n }}\n variant=\"standard\"\n fullWidth\n error={!this.state.clientId}\n disabled={!!disabled}\n label={I18n.t('ra_OAuth Client ID')}\n slotProps={{\n input: {\n endAdornment: this.state.clientId ? (\n <IconButton\n size=\"small\"\n tabIndex={-1}\n onClick={() =>\n this.setState({ clientId: '' }, () =>\n this.onChange(this.props.schema.ownClientId, ''),\n )\n }\n >\n <CloseIcon />\n </IconButton>\n ) : null,\n },\n }}\n />\n ) : null}\n {this.props.schema.ownClientSecret ? (\n <TextField\n value={this.state.clientSecret}\n onChange={e => {\n const value = e.target.value;\n\n this.setState({ clientSecret: value }, () =>\n this.onChange(this.props.schema.ownClientSecret, value),\n );\n }}\n variant=\"standard\"\n fullWidth\n error={!this.state.clientSecret}\n disabled={!!disabled}\n label={I18n.t('ra_OAuth Client secret')}\n slotProps={{\n input: {\n endAdornment: this.state.clientSecret ? (\n <IconButton\n size=\"small\"\n tabIndex={-1}\n onClick={() =>\n this.setState({ clientSecret: '' }, () =>\n this.onChange(this.props.schema.ownClientSecret, ''),\n )\n }\n >\n <CloseIcon />\n </IconButton>\n ) : null,\n },\n }}\n />\n ) : null}\n <Button\n disabled={\n this.state.running ||\n (this.props.schema.ownClientSecret && !this.state.clientSecret) ||\n (this.props.schema.ownClientId && !this.state.clientId)\n }\n endIcon={icon || <CloudUpload />}\n variant=\"contained\"\n onClick={() => this.onOpenUrl()}\n >\n {label}\n </Button>\n {this.state.blocked ? (\n <div style={{ color: 'red', fontSize: 16, marginTop: 20 }}>\n {I18n.t('ra_Please allow popups in your browser for this page!')}\n </div>\n ) : null}\n {this.state.accessTokens ? (\n <div style={{ color: 'green', fontSize: 16, marginTop: 20 }}>\n {this.props.alive\n ? I18n.t(\n 'ra_Successfully authorized. Token valid till %s and will be automatically renewed.',\n validTill,\n )\n : I18n.t(\n 'ra_Successfully authorized. Token valid till %s but it can expire as the instance is not running.',\n validTill,\n )}\n </div>\n ) : null}\n {this.state.pressed ? (\n <>\n <div style={{ width: '100%', margin: '1rem 0 1rem 0' }}>\n <span style={{ marginRight: 4 }}>\n {`${I18n.t('ra_If the button above does not work, you can authorize manually this app by visiting this url')}`}\n :\n </span>\n <br />\n <a\n target={this.props.schema.identifier}\n href={this.url}\n rel=\"noreferrer\"\n >\n {this.url}\n </a>\n </div>\n <TextField\n value={this.state.accessTokens}\n label={I18n.t('ra_Enter the code from that page here')}\n variant=\"standard\"\n onChange={e => {\n let accessTokens = e.target.value;\n if (accessTokens && !accessTokens.startsWith('{')) {\n // convert base64 to string\n accessTokens = atob(accessTokens);\n }\n try {\n const accessTokensParsed: AccessTokens = JSON.parse(accessTokens);\n if (accessTokensParsed.access_token) {\n accessTokensParsed.access_token_expires_on = new Date(\n Date.now() + (accessTokensParsed.expires_in - 10) * 1000,\n ).toISOString();\n this.setState({ accessTokens: JSON.stringify(accessTokensParsed) }, () =>\n this.saveToken(this.state.accessTokens),\n );\n }\n } catch {\n // ignore\n }\n }}\n fullWidth\n />\n </>\n ) : null}\n </div>\n );\n }\n}\n"]}
1
+ {"version":3,"file":"ConfigOAuth2.js","sourceRoot":"./src/","sources":["JsonConfigComponent/ConfigOAuth2.tsx"],"names":[],"mappings":"AAAA,OAAO,KAAK,MAAM,OAAO,CAAC;AAE1B,OAAO,EAAE,MAAM,EAAE,UAAU,EAAE,SAAS,EAAE,MAAM,eAAe,CAAC;AAC9D,OAAO,EAAE,KAAK,IAAI,SAAS,EAAE,WAAW,EAAE,MAAM,qBAAqB,CAAC;AAEtE,OAAO,EAAE,IAAI,EAAE,MAAM,4BAA4B,CAAC;AAElD,OAAO,aAAmE,MAAM,iBAAiB,CAAC;AAmClG,MAAM,CAAC,OAAO,OAAO,YAAa,SAAQ,aAAmD;IACjF,UAAU,CAAsB;IACvB,GAAG,CAAS;IACZ,GAAG,CAAS;IAE7B,YAAY,KAAwB;QAChC,KAAK,CAAC,KAAK,CAAC,CAAC;QAEb,IAAI,CAAC,KAAK,GAAG;YACT,GAAG,IAAI,CAAC,KAAK;YACb,Y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SAAS;wBACb,CAAC;oBACL,CAAC,EACD,SAAS,SACX,CACH,CACN,CAAC,CAAC,CAAC,IAAI,CACN,CACT,CAAC;IACN,CAAC;CACJ","sourcesContent":["import React from 'react';\n\nimport { Button, IconButton, TextField } from '@mui/material';\nimport { Close as CloseIcon, CloudUpload } from '@mui/icons-material';\n\nimport { I18n } from '@iobroker/adapter-react-v5';\n\nimport ConfigGeneric, { type ConfigGenericProps, type ConfigGenericState } from './ConfigGeneric';\nimport type { ConfigItemOAuth2 } from '../types';\n\ndeclare global {\n interface Window {\n attachEvent: Window['addEventListener'];\n detachEvent: Window['removeEventListener'];\n }\n}\n\ninterface ConfigOAuth2Props extends ConfigGenericProps {\n schema: ConfigItemOAuth2;\n}\n\nexport interface AccessTokens {\n access_token: string;\n expires_in: number;\n access_token_expires_on: string;\n ext_expires_in: number;\n token_type: 'Bearer';\n scope: string;\n refresh_token: string;\n client_id: string;\n}\n\ninterface ConfigOAuth2State extends ConfigGenericState {\n accessTokens: string;\n success: boolean;\n blocked: boolean;\n running: boolean;\n pressed: boolean;\n clientId: string;\n clientSecret: string;\n}\n\nexport default class ConfigOAuth2 extends ConfigGeneric<ConfigOAuth2Props, ConfigOAuth2State> {\n private authWindow?: WindowProxy | null;\n private readonly oid: string;\n private readonly url: string;\n\n constructor(props: ConfigOAuth2Props) {\n super(props);\n\n this.state = {\n ...this.state,\n accessTokens: '',\n success: false,\n blocked: false,\n running: false,\n pressed: false,\n clientId: '',\n clientSecret: '',\n };\n\n this.url = `https://oauth2.iobroker.in/${props.schema.identifier}?redirect=true`;\n if (props.schema.scope) {\n this.url += `&scope=${encodeURIComponent(props.schema.scope)}`;\n }\n\n this.oid = `${this.props.oContext.adapterName}.${this.props.oContext.instance}.${this.props.schema.saveTokenIn || 'oauth2Tokens'}`;\n }\n\n async componentDidMount(): Promise<void> {\n super.componentDidMount();\n if (window.addEventListener) {\n window.addEventListener('message', this.onMessage as any, false);\n } else {\n window.attachEvent('onmessage', this.onMessage as any, false);\n }\n\n await this.props.oContext.socket.subscribeState(this.oid, this.onTokensUpdated);\n\n let state: Partial<ConfigOAuth2State> | undefined;\n if (this.props.schema.ownClientId) {\n state = { clientId: ConfigGeneric.getValue(this.props.data, this.props.schema.ownClientId) };\n }\n if (this.props.schema.ownClientId) {\n state ||= {};\n state.clientSecret = ConfigGeneric.getValue(this.props.data, this.props.schema.ownClientSecret);\n }\n\n // read tokens\n const tokens = await this.props.oContext.socket.getState(this.oid);\n if (tokens) {\n const accessTokens: AccessTokens = JSON.parse(tokens.val as string);\n if (new Date(accessTokens.access_token_expires_on).getTime() > Date.now()) {\n state ||= {};\n state.accessTokens = tokens.val as string;\n }\n }\n if (state) {\n this.setState(state as ConfigOAuth2State);\n }\n }\n\n onTokensUpdated = (_id: string, state: ioBroker.State | null | undefined): void => {\n if (state?.val) {\n const accessTokens: AccessTokens = JSON.parse(state.val as string);\n if (new Date(accessTokens.access_token_expires_on).getTime() > Date.now()) {\n if (this.state.accessTokens !== state.val) {\n this.setState({ accessTokens: state.val as string });\n }\n return;\n }\n }\n this.setState({ accessTokens: '' });\n };\n\n componentWillUnmount(): void {\n super.componentWillUnmount();\n if (window.removeEventListener) {\n window.removeEventListener('message', this.onMessage as any, false);\n } else {\n window.detachEvent('onmessage', this.onMessage as any, false);\n }\n this.props.oContext.socket.unsubscribeState(this.oid, this.onTokensUpdated);\n }\n\n saveToken(accessTokens: string): void {\n try {\n if (accessTokens && !accessTokens.startsWith('{')) {\n // convert base64 to string\n accessTokens = atob(accessTokens);\n }\n\n const accessTokensParsed: AccessTokens = JSON.parse(accessTokens);\n if (accessTokensParsed.access_token && accessTokensParsed.refresh_token && accessTokensParsed.expires_in) {\n // Give 10 seconds to user to copy the token\n accessTokensParsed.access_token_expires_on ||= new Date(\n Date.now() + accessTokensParsed.expires_in * 1000,\n ).toISOString();\n if (this.props.schema.ownClientId) {\n accessTokensParsed.client_id = ConfigGeneric.getValue(\n this.props.data,\n this.props.schema.ownClientId,\n );\n }\n\n this.props.oContext.socket\n .setState(this.oid, JSON.stringify(accessTokensParsed), true)\n .catch((e: Error) => console.log(`Error occurred: ${e.toString()}`));\n }\n } catch (e) {\n // ignore\n console.warn(e);\n }\n }\n\n onMessage = (event: MessageEvent): void => {\n if (event.origin !== 'https://oauth2.iobroker.in') {\n return;\n }\n if (\n (typeof event.data === 'string' &&\n event.data.startsWith(`${this.props.schema.identifier}-authentication:`)) ||\n (typeof (event as any).message === 'string' &&\n (event as any).message.startsWith(`${this.props.schema.identifier}-authentication:`))\n ) {\n const parts = (event.data || (event as any).message).split(':');\n if (parts[1] === 'success') {\n this.setState({ accessTokens: parts[2], success: true, pressed: false }, () =>\n this.saveToken(this.state.accessTokens),\n );\n\n // send message to auth window to close it\n this.authWindow?.postMessage('close', event.origin);\n this.authWindow = null;\n } else {\n this.props.onError?.(parts[2]);\n }\n }\n };\n\n onOpenUrl(): void {\n this.authWindow = window.open(\n this.url + (this.props.schema.ownClientId ? `&clientId=${encodeURIComponent(this.state.clientId)}` : ''),\n this.props.schema.identifier,\n );\n if (!this.authWindow || this.authWindow.closed || typeof this.authWindow.closed === 'undefined') {\n this.setState({ blocked: true });\n } else {\n this.setState({ pressed: true });\n }\n }\n\n renderItem(_error?: boolean, disabled?: boolean): React.JSX.Element {\n let validTill = '';\n if (this.state.accessTokens) {\n try {\n const accessTokensParsed: AccessTokens = JSON.parse(this.state.accessTokens);\n validTill = new Date(accessTokensParsed.access_token_expires_on).toLocaleString();\n } catch {\n // ignore\n }\n }\n\n let label: string;\n if (this.state.accessTokens) {\n label = this.props.schema.refreshLabel\n ? this.getText(this.props.schema.refreshLabel)\n : I18n.t(\n 'ra_Renew %s access',\n this.props.schema.identifier[0].toUpperCase() + this.props.schema.identifier.slice(1),\n );\n } else {\n label = this.props.schema.label\n ? this.getText(this.props.schema.label)\n : I18n.t(\n 'ra_Get %s access',\n this.props.schema.identifier[0].toUpperCase() + this.props.schema.identifier.slice(1),\n );\n }\n const icon = this.getIcon();\n\n return (\n <div style={{ width: '100%', margin: '0 0 1rem 0' }}>\n {this.props.schema.ownClientId ? (\n <TextField\n value={this.state.clientId}\n onChange={e => {\n const value = e.target.value;\n\n this.setState({ clientId: value }, () =>\n this.onChange(this.props.schema.ownClientId, value),\n );\n }}\n style={{ marginBottom: 8 }}\n variant=\"standard\"\n fullWidth\n error={!this.state.clientId}\n disabled={!!disabled}\n label={I18n.t('ra_OAuth Client ID')}\n slotProps={{\n input: {\n endAdornment: this.state.clientId ? (\n <IconButton\n size=\"small\"\n tabIndex={-1}\n onClick={() =>\n this.setState({ clientId: '' }, () =>\n this.onChange(this.props.schema.ownClientId, ''),\n )\n }\n >\n <CloseIcon />\n </IconButton>\n ) : null,\n },\n }}\n />\n ) : null}\n {this.props.schema.ownClientSecret ? (\n <TextField\n value={this.state.clientSecret}\n onChange={e => {\n const value = e.target.value;\n\n this.setState({ clientSecret: value }, () =>\n this.onChange(this.props.schema.ownClientSecret, value),\n );\n }}\n style={{ marginBottom: 8 }}\n variant=\"standard\"\n fullWidth\n error={!this.state.clientSecret}\n disabled={!!disabled}\n label={I18n.t('ra_OAuth Client secret')}\n slotProps={{\n input: {\n endAdornment: this.state.clientSecret ? (\n <IconButton\n size=\"small\"\n tabIndex={-1}\n onClick={() =>\n this.setState({ clientSecret: '' }, () =>\n this.onChange(this.props.schema.ownClientSecret, ''),\n )\n }\n >\n <CloseIcon />\n </IconButton>\n ) : null,\n },\n }}\n />\n ) : null}\n <Button\n disabled={\n this.state.running ||\n (this.props.schema.ownClientSecret && !this.state.clientSecret) ||\n (this.props.schema.ownClientId && !this.state.clientId)\n }\n endIcon={icon || <CloudUpload />}\n variant=\"contained\"\n onClick={() => this.onOpenUrl()}\n >\n {label}\n </Button>\n {this.state.blocked ? (\n <div style={{ color: 'red', fontSize: 16, marginTop: 20 }}>\n {I18n.t('ra_Please allow popups in your browser for this page!')}\n </div>\n ) : null}\n {this.state.accessTokens ? (\n <div style={{ color: 'green', fontSize: 16, marginTop: 20 }}>\n {this.props.alive\n ? I18n.t(\n 'ra_Successfully authorized. Token valid till %s and will be automatically renewed.',\n validTill,\n )\n : I18n.t(\n 'ra_Successfully authorized. Token valid till %s but it can expire as the instance is not running.',\n validTill,\n )}\n </div>\n ) : null}\n {this.state.pressed ? (\n <>\n <div style={{ width: '100%', margin: '1rem 0 1rem 0' }}>\n <span style={{ marginRight: 4 }}>\n {`${I18n.t('ra_If the button above does not work, you can authorize manually this app by visiting this url')}`}\n :\n </span>\n <br />\n <a\n target={this.props.schema.identifier}\n href={this.url}\n rel=\"noreferrer\"\n >\n {this.url}\n </a>\n </div>\n <TextField\n value={this.state.accessTokens}\n label={I18n.t('ra_Enter the code from that page here')}\n variant=\"standard\"\n onChange={e => {\n let accessTokens = e.target.value;\n if (accessTokens && !accessTokens.startsWith('{')) {\n // convert base64 to string\n accessTokens = atob(accessTokens);\n }\n try {\n const accessTokensParsed: AccessTokens = JSON.parse(accessTokens);\n if (accessTokensParsed.access_token) {\n accessTokensParsed.access_token_expires_on = new Date(\n Date.now() + (accessTokensParsed.expires_in - 10) * 1000,\n ).toISOString();\n this.setState({ accessTokens: JSON.stringify(accessTokensParsed) }, () =>\n this.saveToken(this.state.accessTokens),\n );\n }\n } catch {\n // ignore\n }\n }}\n fullWidth\n />\n </>\n ) : null}\n </div>\n );\n }\n}\n"]}
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@iobroker/json-config",
3
3
  "description": "This package contains the ioBroker JSON config UI components",
4
- "version": "8.2.14",
4
+ "version": "8.2.15",
5
5
  "author": {
6
6
  "name": "bluefox",
7
7
  "email": "dogafox@gmail.com"