UNPKG

oidc-lib

Version:

A library for creating OIDC Service Providers

166 lines (139 loc) 6.05 kB
<!-- Copyright 2016 Google Inc. Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0 Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License. --> <!DOCTYPE html> <html lang="en"> <head> <title>Minimal Dev Wallet - Wallet Get UI</title> <meta charset="utf-8"> <meta name="viewport" content="width=device-width"> <link href="/personal/css/bootstrap.css" rel="stylesheet"> <link href="/personal/css/chapi_personal.css" rel="stylesheet"> <link href="/personal/fontawesome/css/fontawesome.css" rel="stylesheet"> <link href="/personal/fontawesome/css/solid.css" rel="stylesheet"> <link href="/personal/fontawesome/css/regular.css" rel="stylesheet"> <script src="credential-handler-polyfill.min.js"></script> <script src="web-credential-handler.min.js"></script> <script src="config.js"></script> </head> <body> <div class="container"> <div class="card-panel" id="logged-in"> <div class="row"> <p class="text-right" style="font-size: .5rem; line-height: .6rem"><i>Wallet get() event</i></p> <div class="col-sm-12"> <p id="requestReason" style="line-height: 1.0; font-weight: bold;"></p> <div class="mb-1"> <span style="font-size: .74rem;"><i>Tap <i class="far fa-paper-plane"></i> to send a credential to:</i></span> <br/> <span style="font-weight: bold; line-height:1.0;word-wrap: break-word;" id="requestOrigin"></span> </div> </div> </div> <br/> <div id="userArea"> <p>Your matching credentials are:</p> <div id="card_set" class="card-set"> </div> <div id="card_contents" class="clms_0"> <form id="personal_data"> </form> <input type="hidden" id="scope_info"> <input type="hidden" id="encoded_sts_state_bundle"> <input type="hidden" id="content_module_state"> <input type="hidden" id="client_redirect_uri"> <input type="hidden" id="encoded_sts_state_bundle"> <input type="hidden" id="content_module_state"> </div> </div> <br/> <div class="row"> <button class="btn btn-warning" type="button" id="consent_cancel">Cancel</button> </div> </div> </div> <!--script src="/personal/pwa_start.js"></script--> <script src="/personal/js/pk.js"></script> <script src="/personal/js/claimerClientLib.js"></script> <script src="/personal/js/appOP.js"></script> <script src="/personal/js/jquery-3.2.1.slim.min.js"></script> <script src="/personal/js/popper.min.js"></script> <script src="/personal/js/bootstrap.min.js"></script> <script> async function handleGetEvent() { const event = await WebCredentialHandler.receiveCredentialEvent(); pk.ptools.persona_submission_enabled(true); console.log('Wallet processing get() event:', event); var client_id = event.credentialRequestOrigin; document.getElementById('requestOrigin').innerHTML = client_id; const vp = event.credentialRequestOptions.web.VerifiablePresentation; const query = Array.isArray(vp.query) ? vp.query[0] : vp.query; if(!query.type === 'QueryByExample') { throw new Error('Only QueryByExample requests are supported in demo wallet.'); } const requestReason = query.credentialQuery.reason; document.getElementById('requestReason').innerHTML = requestReason; var scopeInfo = pk.ptools.emptyScopeInfo(); scopeInfo.scopeArray = ['openid'].concat(query.credentialQuery.example.type); document.getElementById('scope_info').value = btoa(JSON.stringify(scopeInfo)); var content_module_state = { client_id: client_id, accessTokenContent: null } document.getElementById('content_module_state').value = btoa(JSON.stringify(content_module_state)); var sts_state_bundle = { contentModuleName: 'personal', code: await pk.util.randomString(), access_token: await pk.util.randomString(), response_type: 'id_token', token_response_callback_info: { name: 'processTokenResult' } } pk.sts.register_token_response_callback('processTokenResult', { function: processTokenResult, event: event } ); var auth_state = { sts_state_bundle: sts_state_bundle, content_module_state: content_module_state } document.getElementById('encoded_sts_state_bundle').value = btoa(JSON.stringify(auth_state)); pk.ptools.paint_cards('selected', scopeInfo); /* refreshUserArea({ shareButton: { text: 'Share', sourceEvent: event } }); */ } function processTokenResult(tokenResult, event){ const vp = { "@context": [ "https://www.w3.org/2018/credentials/v1", "https://www.w3.org/2018/credentials/examples/v1" ], "type": "VerifiablePresentation", "verifiableCredential": [ tokenResult.id_token ] } console.log('wrapping and returning vc:', vp); event.respondWith(Promise.resolve({dataType: 'VerifiablePresentation', data: vp})); } function _personal_chapi_wallet_ui_get_html(){ credentialHandlerPolyfill .loadOnce(MEDIATOR) .then(handleGetEvent); } </script> <script src="https://cdnjs.cloudflare.com/ajax/libs/materialize/1.0.0/js/materialize.min.js"></script> </body> </html>