@recaptime-dev's working patches + fork for Phorge, a community fork of Phabricator. (Upstream dev and stable branches are at upstream/main and upstream/stable respectively.)
hq.recaptime.dev/wiki/Phorge
phorge
phabricator
1<?php
2
3final class PhabricatorConduitTokenHandshakeController
4 extends PhabricatorConduitController {
5
6 public function handleRequest(AphrontRequest $request) {
7 $viewer = $request->getViewer();
8
9 id(new PhabricatorAuthSessionEngine())->requireHighSecuritySession(
10 $viewer,
11 $request,
12 '/');
13
14 $unguarded = AphrontWriteGuard::beginScopedUnguardedWrites();
15 $token = PhabricatorConduitToken::initializeNewToken(
16 $viewer->getPHID(),
17 PhabricatorConduitToken::TYPE_COMMANDLINE);
18 $token->save();
19 unset($unguarded);
20
21 $form = id(new AphrontFormView())
22 ->setUser($viewer)
23 ->appendRemarkupInstructions(
24 pht(
25 'Copy-paste the API Token below to grant access to your account.'))
26 ->appendChild(
27 id(new AphrontFormTextControl())
28 ->setLabel(pht('API Token'))
29 ->setValue($token->getToken()))
30 ->appendRemarkupInstructions(
31 pht(
32 'This will authorize the requesting script to act on your behalf '.
33 'permanently, like giving the script your account password.'))
34 ->appendRemarkupInstructions(
35 pht(
36 'If you change your mind, you can revoke this token later in '.
37 '{nav icon=wrench,name=Settings > Conduit API Tokens}.'));
38
39 return $this->newDialog()
40 ->setTitle(pht('Grant Account Access'))
41 ->setWidth(AphrontDialogView::WIDTH_FULL)
42 ->appendForm($form)
43 ->addCancelButton('/');
44 }
45
46}