Last active
November 23, 2020 20:29
-
-
Save abergs/740110870c2bf2c1e2dabe0256745dae to your computer and use it in GitHub Desktop.
Passwordless examples
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public async Task<IActionResult> TokenVerify(string token) | |
{ | |
var httpClient = new HttpClient(); | |
// use the Passwordless extension functions | |
var result = await httpClient.VerifyPasswordlessToken(new VerifyTokenParameters(Configuration.ApiSecret, token)); | |
if (result.Success) | |
{ | |
Response.Cookies.Append("User", result.Username); | |
} | |
return result; | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public async Task<string> OnPostRegister() | |
{ | |
// get the currently signed in user, perhaps via cookie or HttpContext. | |
Username = Request.Cookies["User"]; | |
var client = new HttpClient(); | |
// get a token that allows registering a passwordless credential for this username | |
var token = await client.GetPasswordlessRegisterToken(new PasswordlessTokenParameters(ApiSecret, Username)); | |
// return the token to the client side code | |
return token; | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
var username = "..."; | |
var p = new PasswordlessClient({ apiKey: "demo:public:1e0a1f9ec6984548..." }); | |
var myToken = await fetch("/example-backend/passwordless/token" + "?username=" + username).then(r => r.text()); | |
await p.register(myToken); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
var username = "..."; | |
var passwordless = new PasswordlessClient({ apiKey: "demo:public:1e0a1f9ec6984548..." }); | |
var token = await passwordless.signin(username); | |
var user = await fetch("/example-backend/passwordless/token/verify?token=" + token).then(r => r.json()); | |
console.log("User is signed in", user); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment