Skip to content

Commit 41fa47b

Browse files
committed
Revert "Support both web and Android sessions"
This reverts commit 661be43.
1 parent 661be43 commit 41fa47b

File tree

4 files changed

+18
-47
lines changed

4 files changed

+18
-47
lines changed

src/apiutils.nim

+7-13
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
# SPDX-License-Identifier: AGPL-3.0-only
2-
import httpclient, asyncdispatch, options, strformat, strutils, uri, times, math, tables
2+
import httpclient, asyncdispatch, options, strutils, uri, times, math, tables
33
import jsony, packedjson, zippy, oauth1
44
import types, auth, consts, parserutils, http_pool
55
import experimental/types/common
@@ -28,27 +28,21 @@ proc getOauthHeader(url, oauthToken, oauthTokenSecret: string): string =
2828

2929
return getOauth1RequestHeader(params)["authorization"]
3030

31-
proc genHeaders*(url: string; session: Session): HttpHeaders =
31+
proc genHeaders*(url, oauthToken, oauthTokenSecret: string): HttpHeaders =
32+
let header = getOauthHeader(url, oauthToken, oauthTokenSecret)
33+
3234
result = newHttpHeaders({
3335
"connection": "keep-alive",
36+
"authorization": header,
3437
"content-type": "application/json",
3538
"x-twitter-active-user": "yes",
3639
"authority": "api.x.com",
3740
"accept-encoding": "gzip",
3841
"accept-language": "en-US,en;q=0.9",
3942
"accept": "*/*",
40-
"DNT": "1",
43+
"DNT": "1"
4144
})
4245

43-
case session.kind
44-
of oauth:
45-
result["authorization"] = getOauthHeader(url, session.oauthToken, session.oauthSecret)
46-
of cookie:
47-
result["authorization"] = "Bearer AAAAAAAAAAAAAAAAAAAAANRILgAAAAAAnNwIzUejRCOuH5E6I8xnZz4puTs%3D1Zv7ttfk8LF81IUq16cHjhLTvJu4FA33AGWWjCpTnA"
48-
result["x-twitter-auth-type"] = "OAuth2Session"
49-
result["x-csrf-token"] = session.ct0
50-
result["cookie"] = &"ct0={session.ct0}; auth_token={session.authToken}"
51-
5246
template fetchImpl(result, fetchBody) {.dirty.} =
5347
once:
5448
pool = HttpPool()
@@ -60,7 +54,7 @@ template fetchImpl(result, fetchBody) {.dirty.} =
6054

6155
try:
6256
var resp: AsyncResponse
63-
pool.use(genHeaders($url, session)):
57+
pool.use(genHeaders($url, session.oauthToken, session.oauthSecret)):
6458
template getContent =
6559
resp = await c.get($url)
6660
result = await resp.body

src/experimental/parser/session.nim

+9-18
Original file line numberDiff line numberDiff line change
@@ -1,24 +1,15 @@
11
import std/strutils
22
import jsony
33
import ../types/session
4-
from ../../types import Session, SessionKind
4+
from ../../types import Session
55

66
proc parseSession*(raw: string): Session =
7-
let session = raw.fromJson(RawSession)
7+
let
8+
session = raw.fromJson(RawSession)
9+
id = session.oauthToken[0 ..< session.oauthToken.find('-')]
810

9-
case session.kind
10-
of "oauth":
11-
let id = session.oauthToken[0 ..< session.oauthToken.find('-')]
12-
result = Session(
13-
kind: oauth,
14-
id: parseBiggestInt(id),
15-
oauthToken: session.oauthToken,
16-
oauthSecret: session.oauthTokenSecret
17-
)
18-
of "cookie":
19-
result = Session(
20-
kind: cookie,
21-
id: 999,
22-
ct0: session.ct0,
23-
authToken: session.authToken
24-
)
11+
result = Session(
12+
id: parseBiggestInt(id),
13+
oauthToken: session.oauthToken,
14+
oauthSecret: session.oauthTokenSecret
15+
)

src/experimental/types/session.nim

-4
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,4 @@
11
type
22
RawSession* = object
3-
kind*: string
43
oauthToken*: string
54
oauthTokenSecret*: string
6-
ct0*: string
7-
authToken*: string
8-

src/types.nim

+2-12
Original file line numberDiff line numberDiff line change
@@ -31,20 +31,10 @@ type
3131
remaining*: int
3232
reset*: int
3333

34-
SessionKind* = enum
35-
oauth
36-
cookie
37-
3834
Session* = ref object
39-
case kind*: SessionKind
40-
of oauth:
41-
oauthToken*: string
42-
oauthSecret*: string
43-
of cookie:
44-
ct0*: string
45-
authToken*: string
46-
4735
id*: int64
36+
oauthToken*: string
37+
oauthSecret*: string
4838
pending*: int
4939
limited*: bool
5040
limitedAt*: int

0 commit comments

Comments
 (0)