Skip to content

Instantly share code, notes, and snippets.

View TBag's full-sized avatar

Todd Baginski TBag

View GitHub Profile
@TBag
TBag / SPFxhttpClientExample.ts
Created February 6, 2017 14:22
How to set headers and body for SPFx httpClient
import { HttpClient, IHttpClientOptions, HttpClientResponse } from '@microsoft/sp-http';
private makeRequest(value1: string, value2: string, value3: string): Promise<HttpClientResponse> {
const postURL = "https://REST-API-URL";
const body: string = JSON.stringify({
'name1': value1,
'name2': value2,
'name3': value3,
@TBag
TBag / SpFxFlowEmailWebPart.ts
Created February 1, 2017 20:02
SpFxFlowEmailWebPart sendEmailViaOffice365Outlook method
private sendEmailViaOffice365Outlook(emailaddress: string, emailSubject: string, emailBody: string): Promise<HttpClientResponse> {
const postURL = this.properties.flowURL;
const body: string = JSON.stringify({
'emailaddress': emailaddress,
'emailSubject': emailSubject,
'emailBody': emailBody,
});
@TBag
TBag / SpFxFlowEmailWebPart.ts
Created February 1, 2017 19:59
SpFxFlowEmailWepPart sendEmail method
private sendEmail() {
if (!this.properties.flowURL) {
this.context.statusRenderer.renderError(this.domElement, "Flow URL is missing. Open the property pane and specify a Flow URL.");
return;
}
if (!this.validateEmail(this.properties.emailAddress)) {
this.context.statusRenderer.renderError(this.domElement, "Email address is not valid. Open the property pane and specify a valid email address.");
return;
}
else {
@TBag
TBag / gist:94fbe8d843c1eefbb1f0
Created March 2, 2015 16:38
GetActiveDirectoryClientmethod from Property Inspection Code Sample. Part of the AuthenticationHelper class found here: https://github.com/OfficeDev/Property-Inspection-Code-Sample/blob/master/PropertyManagerMyApp/PropertyManagerMyApp/Utils/AuthenticationHelper.cs
private async Task<ActiveDirectoryClient> GetActiveDirectoryClient()
{
Uri baseServiceUri = new Uri(AADAppSettings.AADGraphResourceId);
var tenantId = ClaimsPrincipal.Current.FindFirst("http://schemas.microsoft.com/identity/claims/tenantid").Value;
ActiveDirectoryClient activeDirectoryClient =
new ActiveDirectoryClient(new Uri(baseServiceUri, tenantId),
async () => await AcquireTokenAsync());
return activeDirectoryClient;
}
@TBag
TBag / gist:df84f219ac0cdcc315f5
Created March 2, 2015 16:36
CreateADUsersAndGroups method from Property Inspection Code Sample. Part of the AuthenticationHelper class found here: https://github.com/OfficeDev/Property-Inspection-Code-Sample/blob/master/PropertyManagerMyApp/PropertyManagerMyApp/Utils/AuthenticationHelper.cs
public async Task CreateADUsersAndGroups()
{
XmlDocument sampleData = new XmlDocument();
var sampleDataUrl = HttpContext.Current.Request.Url.Scheme + "://" + HttpContext.Current.Request.Url.Authority + "/Content/SampleData.xml";
sampleData.Load(sampleDataUrl);
this.client = await this.GetActiveDirectoryClient();
//VerifiedDomain defaultDomain = await this.GetTenantDefualtDomain();
String defaultDomainValue = System.Configuration.ConfigurationManager.AppSettings["DemoSiteCollectionOwner"].Split('@')[1];
await ParaseXmlAndCreateADGroups(sampleData);
@TBag
TBag / gist:ba5da46466156f5f1eee
Last active August 29, 2015 14:16
CreateDemoData method from Property Inspection Code Sample. Part of the O365SiteProvision controller class found here: https://github.com/OfficeDev/Property-Inspection-Code-Sample/blob/master/PropertyManagerMyApp/PropertyManagerMyApp/Controllers/O365SiteProvisioningController.cs
[HttpPost]
public async Task<ActionResult> CreateDemoData(SuiteLevelWebApp.Models.ProvisionDemoData model)
{
string token = await O365Util.GetAccessToken(ServiceResources.Dashboard);
using (var clientContext = TokenHelper.GetClientContextWithAccessToken(DemoSiteCollectionUrl, token))
{
AuthenticationHelper adHelp =new AuthenticationHelper();
await adHelp.CreateADUsersAndGroups();
SiteProvisioning siteProvisioning = new SiteProvisioning(clientContext);
siteProvisioning.AddSiteContents();