Skip to content

Instantly share code, notes, and snippets.

View nbellocam's full-sized avatar

Nicolás Bello Camilletti nbellocam

View GitHub Profile
@nbellocam
nbellocam / azFuncInvitation.js
Last active May 22, 2021 04:09
This code shows how to invite users to an Office 365 tenant as guest using Microsoft Graph API from an Azure Function
module.exports = function (context, req) {
context.log('JavaScript HTTP trigger function processed a request.');
if (req.query.email && req.query.name) {
const userEmail = req.query.email;
const userDisplayName = req.query.name;
getToken().then(token => {
/* INVITE A USER TO YOUR TENANT */
var options = {
@nbellocam
nbellocam / azFuncNewGroup.js
Created February 6, 2018 18:29
Calling Microsoft Graph API from an Azure Function using JavaScript - Azure Function code
// ...
module.exports = function (context, req) {
context.log('Starting function');
if (req.query.name) {
const name = req.query.name;
context.log('Parameters OK. Next: get token');
getToken().then(token => {
context.log('Token OK. Next: create the group');
createGroup(token, name)
@nbellocam
nbellocam / putting-all-together.js
Created February 6, 2018 18:26
Calling Microsoft Graph API from an Azure Function using JavaScript - putting all together
const name = 'MyGroup';
getToken().then(token => {
console.log('Token OK. Next: create the group');
createGroup(token, name)
.then(result => {
console.log('Everything OK.');
console.log(result);
}).catch(() => {
console.log('An error occurred while creating the group');
@nbellocam
nbellocam / getToken.js
Created February 6, 2018 18:08
Calling Microsoft Graph API from an Azure Function using JavaScript - getToken Function
var adal = require('adal-node');
const TENANT = "{tenant-name-here}.onmicrosoft.com";
const CLIENT_ID = "{Application-id-here}";
const CLIENT_SECRET = "{Application-key-here}";
function getToken() {
return new Promise((resolve, reject) => {
const authContext = new adal.AuthenticationContext(`https://login.microsoftonline.com/${TENANT}`);
authContext.acquireTokenWithClientCredentials(GRAPH_URL, CLIENT_ID, CLIENT_SECRET, (err, tokenRes) => {
@nbellocam
nbellocam / createGroup.js
Last active February 6, 2018 17:45
Calling Microsoft Graph API from an Azure Function using JavaScript - createGroup Function
var request = require('request');
function createGroup(token, name) {
return new Promise((resolve, reject) => {
const options = {
method: 'POST',
url: 'https://graph.microsoft.com/v1.0/groups/',
headers: {
'Authorization': 'Bearer ' + token,
'content-type': 'application/json'
@nbellocam
nbellocam / Container-runner.js
Created November 17, 2017 15:28
This gist show how to create a container instance in Azure using service principal authentication and the Azure SDK
const msRestAzure = require('ms-rest-azure');
const ContainerInstanceManagementClient = require("azure-arm-containerinstance");
const AzureServiceClient = msRestAzure.AzureServiceClient;
const clientId = process.env['CLIENT_ID'];
const secret = process.env['APPLICATION_SECRET'];
const domain = process.env['DOMAIN']; //also known as tenantId
const subscriptionId = process.env['AZURE_SUBSCRIPTION_ID'];
const resourceGroup = 'YourResourceGroupName';

Keybase proof

I hereby claim:

  • I am nbellocam on github.
  • I am nbellocam (https://keybase.io/nbellocam) on keybase.
  • I have a public key whose fingerprint is EB79 EFAA 5DA5 88F2 22E9 B8C0 DCC7 25C1 D211 D902

To claim this, I am signing this object:

@nbellocam
nbellocam / Startup.cs
Created March 14, 2016 13:14
Asp.net core: Configure MVC to use camelCase for json serializer
services.AddMvc().AddJsonOptions(options =>
{
options.SerializerSettings.ContractResolver = new CamelCasePropertyNamesContractResolver();
options.SerializerSettings.DefaultValueHandling = DefaultValueHandling.Include;
options.SerializerSettings.NullValueHandling = NullValueHandling.Ignore;
});