/run/. Copy it from the workflow “Access URL” in the AgentixHub control panel.', 'agentixhub-chat' ) ); } $token = $m[1]; $payload = json_decode( self::b64url( explode( '.', $token )[1] ), true ); if ( ! is_array( $payload ) || ( $payload['iss'] ?? '' ) !== 'agentix-core-api' || ( $payload['sub'] ?? '' ) !== 'workflow-access' || empty( $payload['workflowId'] ) || ! is_scalar( $payload['workflowId'] ) ) { return new WP_Error( 'agentix_url', __( 'The token in this URL is not an AgentixHub workflow access token.', 'agentixhub-chat' ) ); } // The token names the launchpad it was issued for; a different host means the URL was altered. if ( isset( $payload['domain'] ) && strtolower( (string) $payload['domain'] ) !== strtolower( $parts['host'] ) ) { return new WP_Error( 'agentix_url', __( 'This workflow URL does not match the launchpad its token was issued for. Copy the Access URL again from the AgentixHub control panel.', 'agentixhub-chat' ) ); } if ( isset( $payload['exp'] ) && (int) $payload['exp'] < time() ) { return new WP_Error( 'agentix_url', __( 'This workflow URL has expired. Create a new Access URL in the AgentixHub control panel.', 'agentixhub-chat' ) ); } $origin = $parts['scheme'] . '://' . $parts['host'] . ( isset( $parts['port'] ) ? ':' . $parts['port'] : '' ); return array( 'origin' => $origin, 'workflow_id' => (string) $payload['workflowId'], 'org_id' => (string) ( $payload['orgId'] ?? '' ), 'domain' => (string) ( $payload['domain'] ?? $parts['host'] ), ); } public static function current() { $url = (string) Agentix_Chat_Options::get( 'workflow_url' ); return '' === $url ? new WP_Error( 'agentix_not_configured', __( 'No workflow URL configured.', 'agentixhub-chat' ) ) : self::parse( $url ); } private static function b64url( string $s ): string { return (string) base64_decode( strtr( $s, '-_', '+/' ) . str_repeat( '=', ( 4 - strlen( $s ) % 4 ) % 4 ) ); } }