Chromium Code Reviews| OLD | NEW |
|---|---|
| (Empty) | |
| 1 <h2 id="usage">Implementing a Captive Portal Authenticator</h2> | |
| 2 This API allows an Extension to implement an authenticator for captive portals. | |
| 3 The interaction between Extension, Chrome, and the user will be: | |
| 4 <ol> | |
| 5 <li>Using $(ref:setNetworkFilter), the Extension registers for a list of Wi-Fi | |
| 6 networks that it wants to handle captive portals on.</li> | |
| 7 <li>If one of these networks is detected by Chrome, it will appear in the | |
| 8 network list, badged with an icon to indicate that a captive portal handler is | |
| 9 available.</li> | |
| 10 <li>If the user selects such a network, but a captive portal is not detect, | |
|
not at google - send to devlin
2015/03/17 14:35:11
detect -> detected
| |
| 11 Chrome will connect as usual - the Extension will never be involved.</li> | |
| 12 <li>Otherwise, if a captive portal is detected, the user is notified and asked | |
| 13 to authenticate using the registered Extension or whether to visit the captive | |
| 14 portal page.</li> | |
| 15 <li>If the user selects the Extension, Chrome notifies the Extension through | |
| 16 the $(ref:onCaptivePortalDetected) event.</li> | |
| 17 <li>The Extension should now interact with the user if necessary and | |
| 18 authenticate at the captive portal.</li> | |
| 19 <li>Once the Extension finished the authentication, it notifies the API using | |
| 20 $(ref:finishAuthentication) about its success or failure.</li> | |
| 21 </ol> | |
| 22 | |
| 23 <p> | |
| 24 In the Extension, this can look similar to the following snippet: | |
| 25 </p> | |
| 26 | |
| 27 <pre data-filename="background.js"> | |
| 28 var myNetworks = [ | |
| 29 { Type: 'WiFi', SSID: 'MyHotSpot-1' }, | |
| 30 { Type: 'WiFi', SSID: 'MyHotSpot-2' } | |
| 31 ]; | |
| 32 | |
| 33 chrome.networking.config.setNetworkFilter(myNetworks, function() { | |
| 34 if (chrome.runtime.lastError) { | |
| 35 // Handle Error | |
| 36 } | |
| 37 }); | |
| 38 | |
| 39 chrome.networking.config.onCaptivePortalDetected.addListener( | |
| 40 function(networkInfo) { | |
| 41 var guid = networkInfo.GUID; | |
| 42 | |
| 43 // Check at first whether we really care about this network. | |
| 44 // This can look at additional network properties like BSSID that are not | |
| 45 // supported in the filter. | |
| 46 if (isBadNetwork(networkInfo)) { | |
| 47 chrome.networking.config.finishAuthentication(guid, 'unhandled'); | |
| 48 return; | |
| 49 } | |
| 50 checkForMyCaptivePortalServer(function(serverStatus) { | |
| 51 if (serverStatus == 'not-detected') { | |
| 52 chrome.networking.config.finishAuthentication(guid, 'unhandled'); | |
| 53 return; | |
| 54 } | |
| 55 if (serverStatus == 'error') { | |
| 56 chrome.networking.config.finishAuthentication(guid, 'failed'); | |
| 57 return; | |
| 58 } | |
| 59 | |
| 60 // If required, interact with the user, e.g. for registration on first | |
| 61 // usage. Credentials can be cached for subsequent authentications. | |
| 62 ShowUIToRegisterUser(continueAuthentication.bind(null, guid)); | |
| 63 }); | |
| 64 }); | |
| 65 | |
| 66 function continueAuthentication(guid, credentials) { | |
| 67 if (!credentials) { | |
| 68 chrome.networking.config.finishAuthentication(guid, 'failed'); | |
| 69 } | |
| 70 AuthenticateToMyCaptivePortalServer(credentials, function(success) { | |
| 71 chrome.networking.config.finishAuthentication( | |
| 72 guid, success ? 'succeeded' : 'rejected'); | |
| 73 }); | |
| 74 } | |
| 75 </pre> | |
| OLD | NEW |