In this article I will discuss the first iteration of the new GitHub project I created for the O365Token generation. The project is a generic code sample which can be added to your Azure AD websites and ultimately used to create a secure sample Add-In. We will look at how to take the sample code in the GitHub repository and deploy it to your environment.
In the previous article I showed an alternate method for creating an authorization token from within the Outlook client. After receiving encouragement from Simon Jaeger I decided to continue and make this into something to hopefully collaborate on with others.
The repository is hosted here – https://github.com/markyroden/o365Token – clone it to wherever you want (I use Webstorm IDE) and follow these steps:
- Using the instructions posted here, create your Azure AD site and make the redirect URL match the sample/index.html path.
- Modify the following token parameters in app.js to match your application
How it works
In this version of the token generation I combined a number of aspects of the code and streamlined them to work as one file. There only 3 files (not including CSS) involved in this O365Token sample.
- The place holder for the Add-In
- Determines if the code has been opened in an Add-In or as a popup token generator
- If the page opens as an Add-In it causes the pop-up token generation window
- If the page has been opened in the add-in it acts as the recipient of the token generated in the popup
To simplify deployment and maintenance over time I decided it was easier to write the token generation code into the add-in itself. This also helps to reduce the number of changes necessary
Index.html is really just the placeholder for the sample code – all that happens is that it ends up displaying the token once it is generated.
We are using the same /index.html as the Add-In and the popup token generation window as well. The Home.js file determines if index.html has been opened as an Add-In and if so, calls the app.getToken code. If index.html has been opened in the browser the app.returnToken is called.
App.js has three functions:
- Called when index.html as been opened in the Add-in
- Called when index.html has been opened in the popup
- Called from the app.return once a Token has been generated. This is where your actual Add-In code would live in the future.
For the Future
I have a feeling that this ought to be an Angular module. I can see a lot of Add-In code being written as an Angular app and as such it would make sense to include the app.requestToken and app.getToken as something which can be hooked easily into any other angular app.