Page Menu
Home
c4science
Search
Configure Global Search
Log In
Files
F90511696
PhutilPhabricatorAuthAdapter.php
No One
Temporary
Actions
Download File
Edit File
Delete File
View Transforms
Subscribe
Mute Notifications
Award Token
Subscribers
None
File Metadata
Details
File Info
Storage
Attached
Created
Sat, Nov 2, 08:38
Size
2 KB
Mime Type
text/x-php
Expires
Mon, Nov 4, 08:38 (2 d)
Engine
blob
Format
Raw Data
Handle
22090712
Attached To
rPHU libphutil
PhutilPhabricatorAuthAdapter.php
View Options
<?php
/**
* Authentication adapter for Phabricator OAuth2.
*/
final
class
PhutilPhabricatorAuthAdapter
extends
PhutilOAuthAuthAdapter
{
private
$phabricatorBaseURI
;
private
$adapterDomain
;
public
function
setPhabricatorBaseURI
(
$uri
)
{
$this
->
phabricatorBaseURI
=
$uri
;
return
$this
;
}
public
function
getPhabricatorBaseURI
()
{
return
$this
->
phabricatorBaseURI
;
}
public
function
getAdapterDomain
()
{
return
$this
->
adapterDomain
;
}
public
function
setAdapterDomain
(
$domain
)
{
$this
->
adapterDomain
=
$domain
;
return
$this
;
}
public
function
getAdapterType
()
{
return
'phabricator'
;
}
public
function
getAccountID
()
{
return
$this
->
getOAuthAccountData
(
'phid'
);
}
public
function
getAccountEmail
()
{
return
$this
->
getOAuthAccountData
(
'primaryEmail'
);
}
public
function
getAccountName
()
{
return
$this
->
getOAuthAccountData
(
'userName'
);
}
public
function
getAccountImageURI
()
{
return
$this
->
getOAuthAccountData
(
'image'
);
}
public
function
getAccountURI
()
{
return
$this
->
getOAuthAccountData
(
'uri'
);
}
public
function
getAccountRealName
()
{
return
$this
->
getOAuthAccountData
(
'realName'
);
}
protected
function
getAuthenticateBaseURI
()
{
return
$this
->
getPhabricatorURI
(
'oauthserver/auth/'
);
}
protected
function
getTokenBaseURI
()
{
return
$this
->
getPhabricatorURI
(
'oauthserver/token/'
);
}
public
function
getScope
()
{
return
''
;
}
public
function
getExtraAuthenticateParameters
()
{
return
array
(
'response_type'
=>
'code'
,
);
}
public
function
getExtraTokenParameters
()
{
return
array
(
'grant_type'
=>
'authorization_code'
,
);
}
protected
function
loadOAuthAccountData
()
{
$uri
=
id
(
new
PhutilURI
(
$this
->
getPhabricatorURI
(
'api/user.whoami'
)))
->
setQueryParam
(
'access_token'
,
$this
->
getAccessToken
());
list
(
$body
)
=
id
(
new
HTTPSFuture
(
$uri
))->
resolvex
();
try
{
$data
=
phutil_json_decode
(
$body
);
return
$data
[
'result'
];
}
catch
(
PhutilJSONParserException
$ex
)
{
throw
new
Exception
(
pht
(
'Expected valid JSON response from Phabricator %s request.'
,
'user.whoami'
),
$ex
);
}
}
private
function
getPhabricatorURI
(
$path
)
{
return
rtrim
(
$this
->
phabricatorBaseURI
,
'/'
).
'/'
.
ltrim
(
$path
,
'/'
);
}
}
Event Timeline
Log In to Comment