Page Menu
Home
Phabricator
Search
Configure Global Search
Log In
Files
F14399782
PhutilPersonaAuthAdapter.php
No One
Temporary
Actions
Download File
Edit File
Delete File
View Transforms
Subscribe
Mute Notifications
Award Token
Flag For Later
Size
1 KB
Referenced Files
None
Subscribers
None
PhutilPersonaAuthAdapter.php
View Options
<?php
/**
* Authentication adapter for Mozilla's Persona.
*/
final
class
PhutilPersonaAuthAdapter
extends
PhutilAuthAdapter
{
private
$audience
;
private
$assertion
;
private
$accountData
;
public
function
setAssertion
(
$assertion
)
{
$this
->
assertion
=
$assertion
;
return
$this
;
}
public
function
setAudience
(
$audience
)
{
$this
->
audience
=
$audience
;
return
$this
;
}
public
function
getAdapterDomain
()
{
return
'verifier.login.persona.org'
;
}
public
function
getAdapterType
()
{
return
'persona'
;
}
public
function
getAccountEmail
()
{
return
$this
->
getAccountID
();
}
public
function
getAccountID
()
{
if
(
$this
->
accountData
===
null
)
{
$verify_uri
=
'https://verifier.login.persona.org/verify'
;
$data
=
array
(
'audience'
=>
$this
->
audience
,
'assertion'
=>
$this
->
assertion
,
);
list
(
$body
)
=
id
(
new
HTTPSFuture
(
$verify_uri
,
json_encode
(
$data
)))
->
setMethod
(
'POST'
)
->
addHeader
(
'Content-Type'
,
'application/json'
)
->
resolvex
();
$response
=
null
;
try
{
$response
=
phutil_json_decode
(
$body
);
}
catch
(
PhutilJSONParserException
$ex
)
{
throw
new
PhutilProxyException
(
pht
(
'Unexpected Persona response.'
),
$ex
);
}
$audience
=
idx
(
$response
,
'audience'
);
if
(
$audience
!=
$this
->
audience
)
{
throw
new
Exception
(
pht
(
'Mismatched Persona audience: %s'
,
$audience
));
}
if
(
idx
(
$response
,
'status'
)
!==
'okay'
)
{
$reason
=
idx
(
$response
,
'reason'
,
pht
(
'Unknown'
));
throw
new
Exception
(
pht
(
'Persona login failed: %s'
,
$reason
));
}
$this
->
accountData
=
$response
;
}
return
idx
(
$this
->
accountData
,
'email'
);
}
}
File Metadata
Details
Attached
Mime Type
text/x-php
Expires
Tue, Dec 24, 5:46 PM (1 d, 13 h)
Storage Engine
blob
Storage Format
Encrypted (AES-256-CBC)
Storage Handle
6901643
Default Alt Text
PhutilPersonaAuthAdapter.php (1 KB)
Attached To
Mode
rPHU libphutil
Attached
Detach File
Event Timeline
Log In to Comment