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
using System; | |
using System.IdentityModel.Tokens.Jwt; | |
using Microsoft.IdentityModel.Tokens; | |
using Newtonsoft.Json; | |
namespace Whatever | |
{ | |
public class ValidateJSONWebToken : ActionFilterAttribute | |
{ | |
private DataContainer db = new DataContainer(); |
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
string GetAppOnlyAccessToken(string tenantId, string clientId, string clientSecret) | |
{ | |
string url = "https://login.microsoftonline.com/" + tenantId + "/oauth2/v2.0/token"; | |
var request = (HttpWebRequest)WebRequest.Create(url); | |
request.Method = "POST"; | |
request.Accept = "application/json; odata=verbose"; | |
request.ContentType = "application/x-www-form-urlencoded"; | |
string postData = "client_id=" + clientId + "&scope=https://graph.microsoft.com/.default&client_secret=" + clientSecret + "&grant_type=client_credentials"; | |
byte[] postArray = System.Text.Encoding.UTF8.GetBytes(postData); | |
request.ContentLength = postArray.Length; |
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
/*** | |
Simple JavaScript based authentication/authorization for Azure Active Directory (AAD) applications | |
1. Register an app in Azure, make note of client ID (application ID) and redirect URL | |
2. Set Permissions. | |
Note: In order to get an access token for Office 365 API requests, your application will use the OAuth implicit grant flow. You need to update the application's manifest to allow the OAuth implicit grant flow because it is not allowed by default. Set oauth2AllowImplicitFlow to true in app manifest. | |
***/ |
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
byte[] ConvertZipFileToBinary(HttpPostedFileBase zipfile) | |
{ | |
try | |
{ | |
byte[] data = new byte[zipfile.ContentLength]; | |
zipfile.InputStream.Position = 0; | |
zipfile.InputStream.Read(data, 0, zipfile.ContentLength); | |
return data; | |
} | |
catch (Exception e) |