92 lines
2.5 KiB
HTML
92 lines
2.5 KiB
HTML
<!doctype html>
|
|
<html>
|
|
<head>
|
|
<title>Test Google ID Token</title>
|
|
<script src="https://accounts.google.com/gsi/client" async></script>
|
|
<style>
|
|
body {
|
|
font-family: sans-serif;
|
|
padding: 40px;
|
|
max-width: 800px;
|
|
margin: 0 auto;
|
|
}
|
|
pre {
|
|
background: #f5f5f5;
|
|
padding: 15px;
|
|
overflow-x: auto;
|
|
word-wrap: break-word;
|
|
white-space: pre-wrap;
|
|
}
|
|
button {
|
|
padding: 10px 20px;
|
|
margin: 10px 0;
|
|
cursor: pointer;
|
|
}
|
|
.success {
|
|
color: green;
|
|
}
|
|
.error {
|
|
color: red;
|
|
}
|
|
</style>
|
|
</head>
|
|
<body>
|
|
<h1>Test signInWithIdToken</h1>
|
|
|
|
<h3>Step 1: Sign in with Google</h3>
|
|
<div
|
|
id="g_id_onload"
|
|
data-client_id="994294506382-5o3u98qgurnl0b46dsg8she4v0iupkkm.apps.googleusercontent.com"
|
|
data-callback="handleCredentialResponse"
|
|
data-auto_prompt="false"
|
|
></div>
|
|
<div class="g_id_signin" data-type="standard" data-size="large"></div>
|
|
|
|
<h3>Step 2: ID Token</h3>
|
|
<pre id="token-display">Sign in above to get your ID token...</pre>
|
|
|
|
<h3>Step 3: Test the Endpoint</h3>
|
|
<button id="test-btn" disabled onclick="testEndpoint()">Test /api/auth/id-token</button>
|
|
|
|
<h3>Result:</h3>
|
|
<pre id="result">Waiting...</pre>
|
|
|
|
<script>
|
|
let idToken = null;
|
|
|
|
function handleCredentialResponse(response) {
|
|
idToken = response.credential;
|
|
document.getElementById('token-display').textContent = idToken;
|
|
document.getElementById('test-btn').disabled = false;
|
|
console.log('ID Token:', idToken);
|
|
}
|
|
|
|
async function testEndpoint() {
|
|
const resultEl = document.getElementById('result');
|
|
resultEl.textContent = 'Testing...';
|
|
|
|
try {
|
|
const response = await fetch(
|
|
'http://localhost:7130/api/auth/id-token?client_type=mobile',
|
|
{
|
|
method: 'POST',
|
|
headers: { 'Content-Type': 'application/json' },
|
|
body: JSON.stringify({
|
|
provider: 'google',
|
|
token: idToken,
|
|
}),
|
|
}
|
|
);
|
|
|
|
const data = await response.json();
|
|
resultEl.textContent = JSON.stringify(data, null, 2);
|
|
resultEl.className = response.ok ? 'success' : 'error';
|
|
} catch (err) {
|
|
resultEl.textContent = 'Error: ' + err.message;
|
|
resultEl.className = 'error';
|
|
}
|
|
}
|
|
</script>
|
|
</body>
|
|
</html>
|