Skip to content

Get username,password or hash from req.url #17233

Answered by ayame113
rawkakani asked this question in Q&A
Discussion options

You must be logged in to vote

hash

The URL hash value is not sent to the server. Therefore, it is not possible to retrieve the hash value on the server side.
(ref: https://stackoverflow.com/a/317769)

username and password

Username and password information is in the authorization header. This value is the Base64 encoding of ID and password joined by a single colon.

import { serve } from "https://deno.land/std@0.170.0/http/mod.ts";

serve((req) => {
  console.log(req.url);
  console.log(req.headers.get("authorization")); // => "Basic dXNlcjpwYXNz"
  return Response.json({ ok: true });
});
> curl http://user:pass@localhost:8000/

Perhaps this code will be helpful.↓
https://deno.land/x/basic_auth@v1.1.1/mod.ts?source#L36

Replies: 1 comment 1 reply

Comment options

You must be logged in to vote
1 reply
@rawkakani
Comment options

Answer selected by rawkakani
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
2 participants