const result = await withCleanup(async (defer) => {
const fileHandle = await getFileHandle();
defer(() => fileHandle.close());
// Carry on
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
/* | |
* | |
* Purpose of this script: | |
* This login script will be used to generate auth0 tokens in return of AAD id_token generated | |
* for user logged in to their Windows 10 devices. | |
* | |
* Why: | |
* This is similar to native SIWA, that a desktop windows application performs API based request to OS | |
* to authenticate current user, user sees a consent page, and after consent, application receives | |
* id_token of current user’s Azure AD account associated with Windows 11 machine. |
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
/** | |
* Handler that will be called during the execution of a PostLogin flow. | |
* | |
* @param {Event} event - Details about the user and the context in which they are logging in. | |
* @param {PostLoginAPI} api - Interface whose methods can be used to change the behavior of the login. | |
*/ | |
exports.onExecutePostLogin = async (event, api) => { | |
// Craft a signed session token | |
const token = api.redirect.encodeToken({ | |
secret: 'keyboardcat', // IMPORTANT: Read this from event.secrets |
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
async function getTokenFromRulesConfig(user, context, callback) { | |
const m2mClientID = configuration.m2mCID; | |
const m2mClientSecret = configuration.m2mCSecret; | |
let auth0Domain = '<<your_tenant>>.auth0.com'; | |
const moment = require('moment-timezone'); | |
let axios = require('axios'); | |
const country = context.request.geoip.country_name; | |
const data = { | |
user_app_metadata: user.app_metadata, | |
email: user.email, |
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
function (user, context, callback) { | |
//Check if authn method match pwd or social connections | |
const authMethod = context.authentication.methods.find( | |
(method) => { | |
return (method.name === 'pwd' || method.name === 'federated'); | |
} | |
); | |
console.log('auth method is:', authMethod); | |
Auth0 offers passing extra whitelisted params to upstream IdPs. This feature can be used to pass initial screen/page
hint to the upstream IdP.
- PATCH the custom oauth connection to whitelist and alias the upstream param
curl -H "Authorization: Bearer eyJ0eXAiOiJKV1QiLCJhbGciOiJSUzI1NiIsImtpZCI6IlFqVTVRVEpEUmpnd09UUXpOVGxFUlVZeFJURTRNams0TVRFMlFUUkVNVGxGTlRsRE5VWXlRUSJ9." -X PATCH -H "Content-Type: application/json" -d '{"options":{"upstream_params":{"initial_page":{"alias":"login_hint"}}}}' "https://{domain}.auth0.com/api/v2/connections/{id}"
- You can now pass
intial page
as standardlogin_hint
value and auth0 would translate this to the configured outgoing parameter.
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
The MIT License (MIT) | |
Copyright (c) 2018 Pat Allan | |
Permission is hereby granted, free of charge, to any person obtaining a copy | |
of this software and associated documentation files (the "Software"), to deal | |
in the Software without restriction, including without limitation the rights | |
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell | |
copies of the Software, and to permit persons to whom the Software is | |
furnished to do so, subject to the following conditions: |