### Initializing Sketchfab OAuth2 Client and Handling Connection in JavaScript Source: https://github.com/sketchfab/sketchfab-oauth2/blob/master/index.html This snippet initializes the Sketchfab OAuth2 client with a predefined configuration including hostname, client ID, and redirect URI. It then attaches an event listener to a 'connect' button, which, when clicked, initiates the OAuth2 connection process. Upon successful authentication, the grant object is logged; otherwise, any errors are caught and logged to the console. ```JavaScript var config = { hostname: 'sketchfab.com', client_id: 'ig-3miFgAznsYmxUP9VGoN@Chj7ZIrUfAG!UWwne', redirect_uri: 'http://localhost:8000/authSuccess.html' }; var connectButton = document.querySelector('.connect'); var output = document.querySelector('.output'); connectButton.addEventListener('click', function(e){ var client = new SketchfabOAuth2( config ); client.connect().then( function onSuccess( grant ) { console.log( grant ); } ).catch( function onError( error ) { console.error( error ); } ); }, false); ``` -------------------------------- ### Connecting to Sketchfab with OAuth2 in JavaScript Source: https://github.com/sketchfab/sketchfab-oauth2/blob/master/README.md This JavaScript snippet initializes the SketchfabOAuth2 client with necessary configuration details, including the hostname, client ID, and redirect URI. It then attempts to establish a connection, handling both successful grant acquisition and potential errors using Promises. ```JavaScript var config = { hostname: 'sketchfab.com', client_id: 'INSERT_YOUR_CLIENT_ID_HERE', redirect_uri: 'http://example.com/authSuccess.html' }; var client = new SketchfabOAuth2( config ); client.connect().then( function onSuccess( grant ) { console.log( grant ); } ).catch( function onError( error ) { console.error( error ); } ); ``` -------------------------------- ### Including SketchfabOAuth2 Library in HTML Source: https://github.com/sketchfab/sketchfab-oauth2/blob/master/README.md This snippet demonstrates how to include the SketchfabOAuth2 JavaScript library in an HTML page using a ``` -------------------------------- ### Closing Browser Window with JavaScript Source: https://github.com/sketchfab/sketchfab-oauth2/blob/master/authSuccess.html This JavaScript snippet uses `setTimeout` to close the current browser window after a 2-second delay. It's commonly used in OAuth2 flows where a pop-up window needs to close itself after successful authentication, returning control to the parent window or application. No specific dependencies are required beyond a standard browser environment. ```JavaScript setTimeout(function(){ window.close(); }, 2000); ``` === COMPLETE CONTENT === This response contains all available snippets from this library. No additional content exists. Do not make further requests.