|
| 1 | +--- |
| 2 | +import { Code, Aside } from '@astrojs/starlight/components'; |
| 3 | +import { getLapisUrl } from '../lapisUrl'; |
| 4 | +import { OnlyIf } from './OnlyIf.tsx'; |
| 5 | +
|
| 6 | +const lapisUrl = getLapisUrl(); |
| 7 | +
|
| 8 | +async function instanceRequiresAuthentication() { |
| 9 | + try { |
| 10 | + const response = await fetch(`${lapisUrl}/sample/info`); |
| 11 | + return response.status === 401; |
| 12 | + } catch (error) { |
| 13 | + console.error('Error checking authentication requirement:', error); |
| 14 | + return false; |
| 15 | + } |
| 16 | +} |
| 17 | +
|
| 18 | +const requiresAuth = await instanceRequiresAuthentication(); |
| 19 | +--- |
| 20 | + |
| 21 | +<Aside type='note' |
| 22 | + >This LAPIS instance <b>{requiresAuth ? 'requires' : 'does not require'} authentication</b> to access its data.</Aside |
| 23 | +> |
| 24 | + |
| 25 | +<p> |
| 26 | + Some LAPIS instances require authentication to access their data. If an instance is configured with authentication, |
| 27 | + you need to include a valid access token in your requests. |
| 28 | +</p> |
| 29 | + |
| 30 | +<h2>Checking if Authentication is Required</h2> |
| 31 | +<p>Try accessing any endpoint without authentication:</p> |
| 32 | + |
| 33 | +<Code lang='bash' code={`curl ${lapisUrl}/sample/info -v`} /> |
| 34 | +<p> |
| 35 | + If authentication is required, you'll receive a <code>401 Unauthorized</code> response and the output will contains something |
| 36 | + like |
| 37 | +</p> |
| 38 | +<Code code='> ...\n< HTTP/1.1 401\n< ...' /> |
| 39 | + |
| 40 | +<p>If the instance is open (no authentication), you'll receive the normal response data.</p> |
| 41 | + |
| 42 | +<h2>Getting an Access Token</h2> |
| 43 | + |
| 44 | +<p> |
| 45 | + Contact the LAPIS instance administrator to learn how to obtain an access token. The method depends on the identity |
| 46 | + provider configured for that instance. Common methods include: |
| 47 | + <ul> |
| 48 | + <li><b>Username/password</b> - Exchange credentials for a token</li> |
| 49 | + <li><b>Client credentials</b> - Use a client ID and secret</li> |
| 50 | + <li><b>OAuth 2.0 flows</b> - Authorization code, device flow, etc.</li> |
| 51 | + </ul> |
| 52 | +</p> |
| 53 | + |
| 54 | +<h2>Making Authenticated Requests</h2> |
| 55 | +<p> |
| 56 | + To make authenticated requests to LAPIS, include the access token in the <code>Authorization</code> header using the <code |
| 57 | + >Bearer</code |
| 58 | + > scheme: |
| 59 | + |
| 60 | + <Code lang='bash' code={`curl -H "Authorization: Bearer YOUR_ACCESS_TOKEN" ${lapisUrl}/sample/aggregated`} /> |
| 61 | +</p> |
0 commit comments