Page Menu
Home
c4science
Search
Configure Global Search
Log In
Files
F93700478
PhutilAuthAdapterPersona.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 30, 19:58
Size
1 KB
Mime Type
text/x-php
Expires
Mon, Dec 2, 19:58 (2 d)
Engine
blob
Format
Raw Data
Handle
22690791
Attached To
rPHU libphutil
PhutilAuthAdapterPersona.php
View Options
<?php
/**
* Authentication adapter for Mozilla's Persona.
*/
final
class
PhutilAuthAdapterPersona
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
=
json_decode
(
$body
,
true
);
if
(!
is_array
(
$response
))
{
throw
new
Exception
(
"Unexpected Persona response: {$body}"
);
}
$audience
=
idx
(
$response
,
'audience'
);
if
(
$audience
!=
$this
->
audience
)
{
throw
new
Exception
(
"Mismatched Persona audience: {$audience}"
);
}
if
(
idx
(
$response
,
'status'
)
!==
'okay'
)
{
$reason
=
idx
(
$response
,
'reason'
,
'Unknown'
);
throw
new
Exception
(
"Persona login failed: {$reason}"
);
}
$this
->
accountData
=
$response
;
}
return
idx
(
$this
->
accountData
,
'email'
);
}
}
Event Timeline
Log In to Comment