fix(route): update The Inithium authentication method (#15797)

* fix: delete deprecated INITIUM_IAP_RECEIPT authentication method

* fix(route): fix username and password authentication method

* chore: update route maintainers

* fix: delete all fields for iap_receipt

* fix: delete finally all IAP_RECEIPT field

* fix: correct login request headers
This commit is contained in:
minty_frankie 2024-06-05 17:40:44 +02:00 committed by GitHub
parent 68a6f621c4
commit f4b05dbe34
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
4 changed files with 5 additions and 28 deletions

View File

@ -1,5 +1,5 @@
import 'dotenv/config';
import randUserAgent from '@/utils/rand-user-agent';
import 'dotenv/config';
import { ofetch } from 'ofetch';
let envs = process.env;
@ -154,7 +154,6 @@ export type Config = {
username?: string;
password?: string;
bearertoken?: string;
iap_receipt?: string;
};
instagram: {
username?: string;
@ -513,7 +512,6 @@ const calculateValue = () => {
username: envs.INITIUM_USERNAME,
password: envs.INITIUM_PASSWORD,
bearertoken: envs.INITIUM_BEARER_TOKEN,
iap_receipt: envs.INITIUM_IAP_RECEIPT,
},
instagram: {
username: envs.IG_USERNAME,

View File

@ -6,7 +6,7 @@ const handler = (ctx) => processFeed('channel', ctx);
export const route: Route = {
path: '/channel/:type?/:language?',
name: '专题・栏目',
maintainers: ['prnake'],
maintainers: ['prnake', 'mintyfrankie'],
parameters: {
type: '栏目,缺省为最新',
language: '语言,简体`zh-hans`,繁体`zh-hant`,缺省为简体',

View File

@ -20,7 +20,7 @@ export const route: Route = {
handler,
example: '/theinitium/author/ninghuilulu/zh-hans',
categories: ['new-media'],
description: 'Web 版认证 token 和 iOS 内购回执认证 token 只需选择其一填入即可。你也可选择直接在环境设置中填写明文的用户名和密码',
description: '需填入 Web 版认证 token, 也可选择直接在环境设置中填写明文的用户名和密码',
features: {
requireConfig: [
{
@ -28,11 +28,6 @@ export const route: Route = {
optional: true,
description: `端传媒 Web 版认证 token。获取方式登陆后打开端传媒站内任意页面打开浏览器开发者工具中 “网络”(Network) 选项卡,筛选 URL 找到任一个地址为 \`api.initium.com\` 开头的请求,点击检查其 “消息头”,在 “请求头” 中找到Authorization字段将其值复制填入配置即可。你的配置应该形如 \`INITIUM_BEARER_TOKEN: 'Bearer eyJxxxx......xx_U8'\`。使用 token 部署的好处是避免占据登陆设备数的额度,但这个 token 一般有效期为两周,因此只可作临时测试使用。`,
},
{
name: 'INITIUM_IAP_RECEIPT',
optional: true,
description: `端传媒 iOS 版内购回执认证 token。获取方式登陆后打开端传媒 iOS app 内任意页面,打开抓包工具,筛选 URL 找到任一个地址为 \`api.initium.com\` 开头的请求,点击检查其 “消息头”,在 “请求头” 中找到 \`X-IAP-Receipt\` 字段,将其值复制填入配置即可。你的配置应该形如 \`INITIUM_IAP_RECEIPT: ef81dee9e4e2fe084a0af1ea82da2f7b16e75f756db321618a119fa62b52550e\``,
},
{
name: 'INITIUM_USERNAME',
optional: true,

View File

@ -39,7 +39,6 @@ export const processFeed = async (model: string, ctx: Context) => {
const key = {
email: config.initium.username,
password: config.initium.password,
iapReceipt: config.initium.iap_receipt,
};
const body = JSON.stringify(key);
@ -59,25 +58,11 @@ export const processFeed = async (model: string, ctx: Context) => {
Accept: 'application/json',
Connection: 'keep-alive',
Authorization: TOKEN,
Origin: `https://theinitium.com/`,
Referer: `https://theinitium.com/`,
'X-Client-Name': 'Web',
},
body,
});
/*
const devices = login.data.access.devices;
for (const key in devices) {
const device = devices[key];
if (device.status === 'logged_in' && !device.logout_at && device.platform === 'web') {
token = 'Bearer ' + device.device_id;
break;
}
}
*/
token = 'Bearer ' + login.data.token;
token = 'token ' + login.data.token;
cache.set('initium:token', token);
}
@ -85,7 +70,6 @@ export const processFeed = async (model: string, ctx: Context) => {
Accept: '*/*',
Connection: 'keep-alive',
Authorization: token,
'X-IAP-Receipt': key.iapReceipt || '',
};
let response;
@ -154,7 +138,7 @@ export const processFeed = async (model: string, ctx: Context) => {
const items = await Promise.all(
articles
.filter((a) => a.article)
.slice(0, token === TOKEN && key.iapReceipt === undefined ? 25 : articles.length)
.slice(0, token === TOKEN ? 25 : articles.length)
.map(async (item) => {
item.article.date = parseDate(item.article.date);
item.article.updated = parseDate(item.article.updated);