AuthorizationService
From OpenSimulator
m (→Edited it to work with source tags) |
|||
Line 23: | Line 23: | ||
'''Example''' | '''Example''' | ||
− | < | + | <source lang=xml> |
<?xml version="1.0" encoding="utf-8"?> | <?xml version="1.0" encoding="utf-8"?> | ||
<AuthorizationRequest xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema"> | <AuthorizationRequest xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema"> | ||
Line 33: | Line 33: | ||
<RegionID>e276e142-a099-4d6d-8f2d-0aad91ede958</RegionID> | <RegionID>e276e142-a099-4d6d-8f2d-0aad91ede958</RegionID> | ||
</AuthorizationRequest> | </AuthorizationRequest> | ||
− | + | </source> | |
− | </ | + | |
The authorization service needs to respond with an XML message that matches an XML serialized AuthorizationResponse object. | The authorization service needs to respond with an XML message that matches an XML serialized AuthorizationResponse object. | ||
'''Example''' | '''Example''' | ||
− | < | + | <source lang=xml> |
<?xml version="1.0" encoding="utf-8"?> | <?xml version="1.0" encoding="utf-8"?> | ||
<AuthorizationResponse xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema"> | <AuthorizationResponse xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema"> | ||
Line 45: | Line 44: | ||
<Message>Rob Smart has been authorized for the region test region.</Message> | <Message>Rob Smart has been authorized for the region test region.</Message> | ||
</AuthorizationResponse> | </AuthorizationResponse> | ||
+ | </source> | ||
− | |||
The '''IsAuthorized''' element must contain either the string '''true''' or the string '''false'''. The '''Message''' element can contain any string, at the moment this message | The '''IsAuthorized''' element must contain either the string '''true''' or the string '''false'''. The '''Message''' element can contain any string, at the moment this message |
Revision as of 04:58, 16 September 2009
The Authorization service is currently just a skeleton to be later expanded, however in grid mode it can be used to communicate an external authorization service.
Configuration
To point your region at an external Authorization service edit the file
bin/config-include/GridCommon.ini
add a section such as the following, altering the URI to point to your authorization server
[AuthorizationService] ; ; change this to your grid-wide authorization server ; AuthorizationServerURI = "http://localhost/auth.php"
Message Formats
When a user attempts to enter a region an HTTP POST will be made to the AuthorizationServerURI you specified in the config. The body of the POST will be an XML serialized AuthorizationRequest object.
Example
<?xml version="1.0" encoding="utf-8"?> <AuthorizationRequest xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema"> <ID>decc5198-9de2-11de-be89-00145eecaa9a</ID> <FirstName>Rob</FirstName> <SurName>Smart</SurName> <Email>user@host.com</Email> <RegionName>test region</RegionName> <RegionID>e276e142-a099-4d6d-8f2d-0aad91ede958</RegionID> </AuthorizationRequest>
The authorization service needs to respond with an XML message that matches an XML serialized AuthorizationResponse object.
Example
<?xml version="1.0" encoding="utf-8"?> <AuthorizationResponse xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema"> <IsAuthorized>true</IsAuthorized> <Message>Rob Smart has been authorized for the region test region.</Message> </AuthorizationResponse>
The IsAuthorized element must contain either the string true or the string false. The Message element can contain any string, at the moment this message
will only be shown on the OpenSim region console.
Example PHP
A basic php example for parsing the Authorization XML and responding.
<?php class AuthorizationResponse { private $m_isAuthorized; private $m_message; public function AuthorizationResponse($isAuthorized,$message) { $this->m_isAuthorized = $isAuthorized; $this->m_message = $message; } public function toXML() { return '<?xml version="1.0" encoding="utf-8"?><AuthorizationResponse xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema"><IsAuthorized>'. $this->m_isAuthorized .'</IsAuthorized><Message>'. $this->m_message .'</Message></AuthorizationResponse>'; } } class AuthorizationRequest { private $m_isAuthorized; private $m_message; public $ID; public $FirstName; public $SurName; public $Email; public $RegionName; public $RegionID; public function parseRequest($request) { $reader = new XMLReader(); $reader->XML($request); while ($reader->read()) { if ($reader->nodeType == XMLReader::ELEMENT) { switch($reader->name) { case 'AuthorizationRequest': //$log->write("AuthorizationRequest element"); break; case 'ID': $reader->read(); $this->ID = $reader->value; break; case 'FirstName': $reader->read(); $this->FirstName = $reader->value; break; case 'SurName': $reader->read(); $this->SurName = $reader->value; break; case 'Email': $reader->read(); $this->Email = $reader->value; break; case 'RegionName': $reader->read(); $this->RegionName = $reader->value; break; case 'RegionID': $reader->read(); $this->RegionID = $reader->value; break; } } } } } $request = @file_get_contents('php://input'); $authReq = new AuthorizationRequest(); $authReq->parseRequest($request); $authResp = new AuthorizationResponse("true","You are authorized"); echo $authResp->toXML(); ?>