<?xml version="1.0" encoding="UTF-8"?><rss xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:atom="http://www.w3.org/2005/Atom" version="2.0" xmlns:cc="http://cyber.law.harvard.edu/rss/creativeCommonsRssModule.html">
    <channel>
        <title><![CDATA[Stories by Stuart Tottle on Medium]]></title>
        <description><![CDATA[Stories by Stuart Tottle on Medium]]></description>
        <link>https://medium.com/@stuarttottle?source=rss-e7aa2ddd4f0------2</link>
        <image>
            <url>https://cdn-images-1.medium.com/fit/c/150/150/0*CrdPXi1MuNFD8KcS.</url>
            <title>Stories by Stuart Tottle on Medium</title>
            <link>https://medium.com/@stuarttottle?source=rss-e7aa2ddd4f0------2</link>
        </image>
        <generator>Medium</generator>
        <lastBuildDate>Sun, 29 Nov 2026 22:53:22 GMT</lastBuildDate>
        <atom:link href="https://medium.com/@stuarttottle/feed" rel="self" type="application/rss+xml"/>
        <webMaster><![CDATA[yourfriends@medium.com]]></webMaster>
        <atom:link href="http://medium.superfeedr.com/" rel="hub"/>
        <item>
            <title><![CDATA[How to use the Fetch API in Angular]]></title>
            <link>https://stuarttottle.medium.com/use-the-fetch-api-in-angular-1acafa67bbf2?source=rss-e7aa2ddd4f0------2</link>
            <guid isPermaLink="false">https://medium.com/p/1acafa67bbf2</guid>
            <category><![CDATA[angular]]></category>
            <category><![CDATA[angular-http-service]]></category>
            <category><![CDATA[http-client]]></category>
            <category><![CDATA[javascript]]></category>
            <category><![CDATA[fetch]]></category>
            <dc:creator><![CDATA[Stuart Tottle]]></dc:creator>
            <pubDate>Sat, 23 Jan 2021 20:02:33 GMT</pubDate>
            <atom:updated>2021-01-24T14:13:30.719Z</atom:updated>
            <content:encoded><![CDATA[<p>How to use the Fetch API to make network requests in Angular rather than using the built-in xhr service.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*04Fqp2bAoOBH49kyxhQWTA.png" /></figure><p>The reason I did this was to understand how Angular creates network requests in the internal workings. I’ve been developing in React for the last few years and wondered why Angular does not use Fetch when returning to Angular.</p><p>I don’t think there is a reason to use Fetch in Angular as the existing xhr service is fine. There are pro and cons with both which are already well documented on the internet so will not cover that here.</p><p>You can see the Angular xhr backend service <a href="https://github.com/angular/angular/blob/master/packages/common/http/src/xhr.ts">here</a>.</p><p>I’ve used fromFetch from the <a href="https://rxjs-dev.firebaseapp.com/api/fetch/fromFetch">RxJS</a> library to handle aborting and emitting the response from Fetch. I also copied the xhr tests from the Angular repo and updated the tests to pass without changing the assertions, I couldn&#39;t replicate everything, but I feel I covered the important tests.</p><p>You should be able to provide the Fetch service in one of your Angular modules and you won’t need to make any changes to your existing requests/interceptors that use the httpClient, your tests will also work as before as the HttpClientTestingModule uses its own HttpBackend</p><p>Questions, comments and improvements are very welcome.</p><p>Many thanks for reading and the fetch service can be found below — there is also an example repo with tests which can be found <a href="https://github.com/stottle-uk/stottle-angular-fetch-api">here</a>.</p><p><a href="https://github.com/stottle-uk/stottle-angular-fetch-api">stottle-uk/stottle-angular-fetch-api</a></p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/7c662563a5ca4d84929d09fbe93bb70f/href">https://medium.com/media/7c662563a5ca4d84929d09fbe93bb70f/href</a></iframe><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=1acafa67bbf2" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Is a Monorepo a good idea?]]></title>
            <link>https://stuarttottle.medium.com/is-a-monorepo-a-good-idea-e3cbe41a84fb?source=rss-e7aa2ddd4f0------2</link>
            <guid isPermaLink="false">https://medium.com/p/e3cbe41a84fb</guid>
            <category><![CDATA[monorepo]]></category>
            <category><![CDATA[javascript]]></category>
            <category><![CDATA[software-development]]></category>
            <category><![CDATA[nx]]></category>
            <category><![CDATA[programming]]></category>
            <dc:creator><![CDATA[Stuart Tottle]]></dc:creator>
            <pubDate>Sun, 10 May 2020 10:49:02 GMT</pubDate>
            <atom:updated>2020-05-10T10:49:02.941Z</atom:updated>
            <content:encoded><![CDATA[<p>An investigation into how we can store code and share features, services and config between deployed applications to maintain standards and save time.</p><p>Imagine we are working on a greenfield project where one of the requirements is to breakdown a large and ageing monolithic application into microservices and a new User Interface — you know the drill :)</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*0mRJkKplKUTWQ4b1.jpg" /></figure><p>The goal is to split the current monolith into many small web applications with fewer responsibilities which will use a new backend microservice architecture to persist data.</p><p>Let&#39;s start with a few questions</p><ul><li>What problems in the organisation would a Monorepo solve?</li><li>Will storing all the code in a single place rather than individual repositories give unnecessary constraints?</li><li>Should frontend and backend code be in the same code repository?</li><li>Is the organisation structure/hierarchy set up in such a way which could cause conflict on the approach for shared features?</li><li>Do you need to share code and by whom will it be consumed?</li><li>Should code be as close as possible to its consumer and should further abstractions be added when it’s the only option?</li></ul><blockquote>NB: I give some opinions based on what we did at the end</blockquote><h3>Considerations</h3><p>To help answer the questions, let’s consider a few things</p><p>Is a code repository the document that explains how applications work and should developers find a familiar and consistent pattern across projects within an organisation (and beyond)?</p><p>Are you using version control to help manage code (i hope so)?</p><p><strong>Will a monorepo make it easier for your organisation</strong> to maintain</p><ul><li>Shared Features (eg auth, analytics, forms, utilities)</li><li>Shared Services (Data access, HTTP, PubSub, client state)</li><li>Branding and styling of User Interfaces (UI)</li><li>Consistency for User Experiences (UX)</li><li>Code Linting/Formatting</li><li>External Packages/Dependencies and their versions</li><li>Build times</li><li>Documentation</li><li>Repository metrics and reports</li><li>Deployment config/coordination</li><li>Deployments for different environments</li><li>Prototypes and Spikes</li><li>The responsibility of shared code</li><li>Intellectual property</li><li>Access for internal staff, outsources and contractors</li><li>A codebase with many contributors</li></ul><p>Let’s have a look at the available options for storing code</p><ul><li>Monorepo</li><li>Reference Repository</li><li>Polyrepo</li><li>Copy and Paste</li></ul><h3>Monorepo</h3><p>Create a single repository to store all the code for all solutions. It might take a lot of work to create something bespoke so it makes sense to investigate tools and frameworks that would help manage applications and libraries within a single repo.</p><h4>Pros (Perceived)</h4><ul><li>Easier to maintain external packages/dependencies (complexity is added with more languages)</li><li>Single store for code styles, formatting and linting across solutions</li><li>Everyone knows what everyone is working on via the PR’s on the same repository</li><li>Packages can also be released as NPM packages if required</li><li>Tests can be run across all platforms when a change is made to a shared service/feature/package</li></ul><h4>Cons (Perceived)</h4><ul><li>Yet another CLI</li><li>Won’t solve external dependencies issue</li><li>Overly complex for small projects</li><li>IP for all projects in a single place</li><li>Restricting access to apps/libs for certain teams/outsourcers</li><li>Possible longer build times</li><li>Repository size</li><li>Organisation Structure</li><li>Other opinion based reasons :)</li></ul><h3>Reference Repo</h3><p>Create a reference repo into which all shared features are added eg</p><ul><li>Shared Styles</li><li>Shared Services</li><li>Building apps (base build and deployment config)</li><li>Linting/formating</li></ul><p>Each new project forks the reference app and adds all the other packages required for the rest of the solution. Changes to the reference app can then be merged into the fork.</p><h4>Pros</h4><ul><li>Shared packages can be kept in sync across platforms</li></ul><h4>Cons</h4><ul><li>Loads of code that might not be required in a fork</li><li>Requires discipline to merge in the reference repo as often as it changes</li><li>The fork can easily get out of sync with the reference app</li><li>Do not know if a change in a shared package will break something in a fork until it is merged, which might mean it will never be merged</li></ul><h3>Polyrepo</h3><p>Create individual repositories for each solution and use private and/or public Packages to share code between platforms.</p><h4>Pros</h4><ul><li>Public packages are good for PR in the engineering community with supporting Articles and Blogs</li><li>Clear responsibilities</li></ul><h4>Cons</h4><ul><li>Time-consuming to maintain and developers will always take the path of least resistance</li><li>Another layer of security is required (AuthTokens) when accessing Private packages</li></ul><h3>Copy and Paste</h3><p>Copy and Paste similar functionality between projects</p><h4>Pros</h4><ul><li>Quick and dirty — easy to get quick results</li></ul><h4>Cons</h4><ul><li>Well…</li></ul><h3>Findings</h3><p>I started writing the above a while back for work and then made it more generic for the article. I was going to publish it to medium but didn’t think it said anything new or exciting, but to report 4 months later, I hope the following will help someone make a decision on whether they should create a Monorepo.</p><p>We ended up using <a href="https://nx.dev/">NX</a> to create a Monorepo just for the frontend code and the backend microservices are in separate individual repositories. It is working well for us at the moment.</p><p>Our organisation is split into three cross-functional teams, and the frontend Monorepo contains React web applications to view and capture data and a chrome browser extension (all are being used in production already). More web apps are on the horizon as we move more features from the monolith.</p><p>We quickly found fortnightly meetings with the frontend engineers to discuss changes and the approach to new work provided a lot of value. We only build for what we know and only add abstractions and shared code when it is needed and not because it seems like something we should do.</p><p>We have created shared libraries for an HTTP Client, authentication, forms, styling patterns and features shared between the web apps and browser plugin. The shared libraries, which look like NPM packages when imported in TypeScript, enabled us to turn around a third application in good time as we re-used a lot of form, layout and deployment code.</p><p>The web apps use the <a href="https://nx.dev/react/cli/build">NX React build config</a> and the browser extension extends the default build config with custom webpack config. The CI/CD pipelines for each application watch specified directories and build/test/lint/deploy only when files in those directories have changed.</p><p>We have defined global settings for prettier and eslint config to maintain standards which can be overridden for each application/library if required (we’ve not had to do this).</p><p>We also recently updated the NPM packages in the repo using the NX Migrate command which took about 30 minutes (includes minor code updates for API changes).</p><h3>Conclusion</h3><p>Is a Monorepo a good idea? As always, it depends… We felt creating a Repository just for the frontend code would give us what we need due to the available tooling.</p><p>We chose <a href="https://nx.dev/">NX</a> as it appears to be Enterprise friendly and is run by <a href="https://medium.com/u/76fc1db4149b">Victor Savkin</a> who appears to be a smart guy and we’re happy to follow the opinions the CLI provides.</p><p>Some might now debate using the term Monorepo as the repository only contains a subsection of the organisations’ code, but it’s only a name and I would say organise your code in a way that makes sense for your organisation and understand the constraints with what whatever method you chose.</p><p>The organisation and engineers also needed to adapt to a new way of working and is providing value for us at the moment with good communication across the teams.</p><p>I’m sure the organisation for which I work would like the problems Google, Facebook and Microsoft are having with lots of code, but we’re are not that size. We are aware that some applications and code might not belong in the Monorepo and we have to remind ourselves of the responsibilities, considerations and problems we are trying to solve with having a lot of code in the same repository.</p><h3>Links</h3><ul><li><a href="https://nx.dev/">Nx: Smart Repos · Fast Builds</a></li><li><a href="https://github.com/lerna/lerna">GitHub - lerna/lerna: A tool for managing JavaScript projects with multiple packages.</a></li><li><a href="https://medium.com/@mattklein123/monorepos-please-dont-e9a279be011b">Monorepos: Please don’t!</a></li></ul><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=e3cbe41a84fb" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Comparing the same feature written in React and Angular]]></title>
            <link>https://medium.com/better-programming/comparing-the-same-feature-written-in-react-and-angular-3f6ae04ceef6?source=rss-e7aa2ddd4f0------2</link>
            <guid isPermaLink="false">https://medium.com/p/3f6ae04ceef6</guid>
            <category><![CDATA[angular]]></category>
            <category><![CDATA[react]]></category>
            <category><![CDATA[javascript]]></category>
            <category><![CDATA[azure-services]]></category>
            <category><![CDATA[programming]]></category>
            <dc:creator><![CDATA[Stuart Tottle]]></dc:creator>
            <pubDate>Mon, 11 Nov 2019 16:29:30 GMT</pubDate>
            <atom:updated>2019-11-12T17:29:14.950Z</atom:updated>
            <content:encoded><![CDATA[<h3>Comparing the Same Feature Written in React and Angular</h3><p>The requirement of this feature is to upload files to Azure Blob Storage and then allow the user to list, delete, and download the uploaded items. Both solutions depend on the <a href="https://www.npmjs.com/package/@azure/storage-blob">@azure/storage-blob</a> NPM package, and <a href="https://www.npmjs.com/package/rxjs">rxjs</a> has been added to the React project.</p><p>The projects use TypeScript, React 16.11, Angular 8.2.13, and RxJS 6.4.0.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/700/0*BUmHwr2GcOQD6CUr.png" /></figure><h3>Background</h3><p>I recently wrote two articles about uploading to Azure Blob Storage using <a href="https://medium.com/@stuarttottle/upload-to-azure-blob-storage-with-react-34f37805fdfc">React</a> and <a href="https://medium.com/@stuarttottle/upload-to-azure-blob-storage-with-angular-8-2ed80dfc6672">Angular</a> and ended up creating two projects with identical components and services that had the same name and the same functionality in both solutions. So I thought it’d be interesting to write a comparison on a specific feature rather than describing high-level differences.</p><p>You can find the solutions on GitHub, which have been created using their associated CLI tool (<a href="https://cli.angular.io/">Angular CLI</a>, <a href="https://create-react-app.dev/">Create React App</a>)</p><ul><li><a href="https://github.com/stottle-uk/stottle-angular-blob-storage">Angular</a></li><li><a href="https://github.com/stottle-uk/stottle-react-blob-storage">React</a></li></ul><h3>Solution Overview</h3><p>Both solutions utilise viewState services and have a dedicated service to wrap functionality in the @azure/blob-storage NPM package. I avoided Redux as I didn’t want to add further dependencies to the projects.</p><p>The components subscribe to observables in the viewState services when displaying data and call functions on the viewState service for sharing captured data. They have minimal responsibilities and contain no business logic.</p><p>The main differences in the structure of the two solutions are:</p><ul><li>File-naming conventions</li><li>The Angular solution has an azure-storage feature module so it can be imported into other modules.</li><li>The Angular solution has a token.ts file which contains the factory function to create the BlobServiceClient for the injection token</li><li>The React solution has a contexts file to manage how the components interact with the viewState services</li></ul><p>The same style sheet has been used in both solutions and is very basic and minimal.</p><p>We’ll compare a few components in the solutions to highlight differences, and I&#39;ve included an opinion on how similar functionality can be achieved in the frameworks.</p><p>It’s also worth noting the services are identical apart from the Angular @Injectable decorator for dependency injection.</p><p>I’m not going to cover dependency injection — React may be a better choice for you if you’re not yet familiar with the concept.</p><h3>App Component</h3><p>The app component brings all our components together for the layout and is the entry point to the feature.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*1bQWAnDn02hA6IO0Nu5wAg.png" /><figcaption>Angular on the left; React on the right</figcaption></figure><p>In Angular, the CSS classes are added to the components as they’re treated like HTML elements in the DOM.</p><p>In React, the CSS classes are declared inside the components in this solution. It’s worth noting, we couldn’t do this in Angular without changing the shared CSS structure (the CSS is badly structured — not a limitation on Angular).</p><p>In my opinion, the React component is more intuitive. It has many imports, but this makes it easier to find which components are being used (and typos will be obvious). Also, components that don’t have child elements can be closed with shorthand syntax.</p><h3>File-Upload Component</h3><p>The component displays a button that opens the input-file dialogue when clicked. The selected files are then supplied to the uploadItems function on the viewState state service.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*X3xXn4uP_Vne9DmVdaaiQQ.png" /><figcaption>Angular on the left; React on the right</figcaption></figure><h4>Referencing component-HTML elements</h4><p>In Angular, the fileInput property on the component uses the @ViewChild decorator and the #fileInput attribute to reference the input element.</p><p>In React, the inputFileRef const is assigned to the ref prop of the input and uses the useRef hook to get the reference.</p><p>I can’t decide which approach is the most intuitive.</p><h4>Handling events</h4><p>In Angular, the (change) event on the input is bound to the onSelected function. It uses the framework parentheses convention for binding to events and uses the $event keyword to get a reference to the event data.</p><p>In React, theonChange event is bound to a function which calls the showFileDialog method with the selected files.</p><p>The React approach is more intuitive to me as it doesn&#39;t rely on framework-specific conventions and is all strongly typed.</p><h4>Update the view state</h4><p>In Angular, the BlobUploadsViewStateService is injected into the component, and the onSelected method calls the uploadItems method on the service.</p><p>In React, we get a reference to the BlobUploadsViewState service with the useContext hook to call the uploadItems method on the context.</p><p>I prefer the Angular approach as dependency injection and Angular modules leans towards a more obvious application structure as each module is a feature with specific functionality.</p><h3>Items-Uploaded Component</h3><p>The component displays a list of files the user has uploaded with the upload progress.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*h4zmFCD3emjsWwflHgycew.png" /><figcaption>Angular on the left; React on the right</figcaption></figure><h4>Getting view-state data</h4><p>In Angular, the uploads$ property on the component is assigned to the value of the uploadedItems$ property from the viewState service. The async pipe in the template manages the subscription to the observable, and we loop through each item using the the *ngFor framework-specific syntax.</p><p>In React, there’s a lot more ceremony to manage the subscription to the observable as we’re using useEffect.</p><p>I still prefer the React version, though, as we could create a hook (or use a <a href="https://www.npmjs.com/package/rxjs-hooks">library</a>) to manage the observable subscription and remove the ceremony around the effect. We are also using JavaScript to map the items in the array to HTML/JSX elements rather than using framework-specific syntax/pipes.</p><h3>Selected-Container Component</h3><p>The component displays information about the Azure Blob Container the user has selected in the UI. It also renders the child components that rely on the name of the container name in the viewState services.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*8qqdD_mXnTS1iU0Yyv4D8w.png" /><figcaption>Angular on the left; React on the right</figcaption></figure><h4>Display-child components</h4><p>In Angular, &lt;ng-content&gt; is used to render the child components and the framework-specific &lt;ng-container&gt; element, and an *ngIf is used to hide content when the user has not yet selected a container. The subscription for the selectedContainer$ is managed with the framework-specific async pipe.</p><p>In React, the children prop is used to render the child components, and the library-specific &lt;&gt;&lt;/&gt; is returned when the user hasn’t selected a container in the UI. The props for the component are also set as an HTMLDivElement type so we can add HTML attributes when referencing the component. The attributes are then added to the div element with {...rest}.</p><p>Again, I prefer the React version as we’re avoiding framework-specific syntax, and the ceremony can be removed around the effect so a small compact function component would remain.</p><h3>Conclusion</h3><p>Angular and React offer different approaches to the same problem, I’ve worked on more Angular Projects than React and learnt Angular first, but I’m glad I know both and feel I’m a better developer for it.</p><p>Angular does more out of the box and is a framework with opinions that when followed, can make for rapid development. But you’ll be spending a lot of your time reading documentation, and RxJS has a steep learning curve. You might not get the best out of Angular if you don’t know RxJS.</p><p>React is simpler to get up and running, and the Hooks API is really useful — but I think it’s quite easy to create a spaghetti project if time isn’t given to refactor when the project grows.</p><p>Also, it’s better to understand and appreciate the differences rather than take sides and be rigid with opinions.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=3f6ae04ceef6" width="1" height="1" alt=""><hr><p><a href="https://medium.com/better-programming/comparing-the-same-feature-written-in-react-and-angular-3f6ae04ceef6">Comparing the same feature written in React and Angular</a> was originally published in <a href="https://betterprogramming.pub/">Better Programming</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Upload to Azure Blob Storage with React]]></title>
            <link>https://stuarttottle.medium.com/upload-to-azure-blob-storage-with-react-34f37805fdfc?source=rss-e7aa2ddd4f0------2</link>
            <guid isPermaLink="false">https://medium.com/p/34f37805fdfc</guid>
            <category><![CDATA[azure-services]]></category>
            <category><![CDATA[blob-storage]]></category>
            <category><![CDATA[javascript-frameworks]]></category>
            <category><![CDATA[react]]></category>
            <category><![CDATA[javascript-development]]></category>
            <dc:creator><![CDATA[Stuart Tottle]]></dc:creator>
            <pubDate>Thu, 07 Nov 2019 11:16:05 GMT</pubDate>
            <atom:updated>2019-11-10T11:53:16.401Z</atom:updated>
            <content:encoded><![CDATA[<p>How to upload multiple files to blob storage in a browser with a <em>Shared Access Signature</em> (SAS) token generated from your back-end.</p><p>We’ll use React 16.11 and the <a href="https://www.npmjs.com/package/@azure/storage-blob">@azure/storage-blob</a> library to upload the files.</p><p>The final code is on <a href="https://github.com/stottle-uk/stottle-react-blob-storage">Github</a> which also contains examples on listing containers, blob items and deleting and downloading blob items.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*dk4PZkdTrKuzbL7EAmQe-g.png" /></figure><p>We’ll go over</p><ul><li>Creating a component to select and upload files</li><li>Creating a service to manage view state for the uploads</li><li>Securing the upload to Blob Storage with a SAS token</li><li>Creating a service to wrap the uploadBrowserData method in the @azure/storage-blob library to upload a file to Blob Storage</li><li>Creating a component to display upload progress</li></ul><h3>Create File Upload Component</h3><p>The InputFileComponent component allows the user to select one or more files to upload</p><p>We’ll cover</p><ol><li>Selecting one or more files to upload</li><li>Calling the method on the view state service to start the upload</li></ol><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/1ba69b6c0b139a107c01992e5dae8e65/href">https://medium.com/media/1ba69b6c0b139a107c01992e5dae8e65/href</a></iframe><h4>What’s happening?</h4><p>We’re getting the upload service functionality with useContext so that view state can remain outside of the component lifecycle.</p><p>The input is hidden and the file dialogue is opened with the button. The uploadItems method is called on the BlobUploadsViewStateService when the user selects files. We could add some validation here, but to me, it makes more sense to validate in the view state service.</p><h3>Create uploads view state service</h3><p>The BlobUploadsViewStateService service manages the shared view state for the components. I’m quite familiar with redux patterns so I’ve created a service into which you can supply items to trigger actions and have observables listening for changes. It also means we can keep the business logic out of the components and the components will generally have a single responsibility.</p><p>We’ll cover</p><ol><li>Listing to an observable to trigger uploads</li><li>Getting a SAS token</li><li>Uploading a file to blob storage</li><li>Keeping a list of all upload progress in the view state</li></ol><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/713a26f61dfa2a7432bbf91f18c04b97/href">https://medium.com/media/713a26f61dfa2a7432bbf91f18c04b97/href</a></iframe><h4>What’s happening?</h4><p>The public uploadItems method accepts a list of files and calls the next method on the uploadQueueInner$ subject. The uploadQueue$ getter is listening to the subject as an observable and will emit each file in the files list as a separate item. This is one place the files could be validated.</p><p>The uploadedItems$ property is listening to the uploadQueue$ and will call the uploadFile method in the service for each file item emitted. Something will need to subscribe to the uploadedItems$ for uploads to start and display upload progress (we’ll cover this below in the upload progress component)</p><p>The uploadFile method gets the latest SAS token and calls the uploadToBlobStorage on the Blob Storage Wrapper Service with the token and file details (we’ll cover this below).</p><p>The uploadToBlobStorage method returns an observable that emits the loadedBtyes each time it changes and can be used to track upload progress.</p><p>We then map the upload response to a percentage in the mapUploadResponse method and include extra detail. The method also has the startWith operator so any subscribers will be notified as soon as the upload starts rather than waiting for progress to be emitted.</p><p>We then call the finalise method when the upload is complete to refresh the items in the blob container.</p><p>The mapped response from the uploadFile method is then piped into a custom scan operator function to reduce the emitted values into an array. This allows us to store all uploads in progress and add further uploads when uploads are already in progress.</p><h3>Secure the upload with a SAS token</h3><p>The service above calls a method to get a SAS before every upload from a service. The method in this code example returns a hard codes SAS token I generated in the Azure portal, but in the real world, you would call an API to generate and return the SAS token. Here is a basic example in C# using the Azure.Storage.Blobs (v12.0.0) package to generate an Account SAS which can be used for many operations. You can also create SAS tokens for specific blob items or containers when you want/need to be more granular.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/2ce6b4a726054717f423fa76d991b46d/href">https://medium.com/media/2ce6b4a726054717f423fa76d991b46d/href</a></iframe><h3>Wrap the uploadBrowserData method in the @azure/storage-blob library</h3><p>We wrap the @azure/storage-blob library to return observables rather than promises as it works well when emitting progress events.</p><p>We’ll cover</p><ol><li>Creating a blobServiceClient from the @azure/storage-blob library</li><li>Calling the uploadBrowserData method and returning an observable of the loadedBytes</li></ol><p>Here is a snippet from the <a href="https://github.com/stottle-uk/stottle-react-blob-storage/blob/master/src/azure-storage/services/BlobStorageService.ts">full service</a></p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/2a34476422db126b4a593468c1c40884/href">https://medium.com/media/2a34476422db126b4a593468c1c40884/href</a></iframe><h4>What’s happening?</h4><p>The uploadToBlobStorage method in the wrapper service accepts the file to be uploaded and an object with the SAS token. The blobServiceClient was created using a connection string which included the SAS token.</p><p>We then pass the BlockBlobClient created using the blobServiceClient and the file into the uploadFile method which wraps the uploadBrowserData method. We listen to the onProgress events and emit the value each time the progress changes. We then emit the file size and complete the observable when the upload completes.</p><h3>Create a component to display upload progress</h3><p>In this code example, the view state services manage the shared data and the components display the data. This good practice allows us to separate the file input and upload progress components and keeps our components small and have fewer responsibilities (hopefully just one).</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/d65808ffa66a0bd988ae1b776a635a33/href">https://medium.com/media/d65808ffa66a0bd988ae1b776a635a33/href</a></iframe><h4>What’s happening?</h4><p>We get the uploads view state from the context and utilise theuseEffect hook to manage the subscription to uploadedItems$ on the BlobUploadsViewStateService service we referenced above.</p><p>We then update the components state with the items and render the items to the user.</p><h3>Conclusion</h3><p>This is one way the upload to Azure blob storage could be implemented and I’ve attempted to demonstrate a basic architecture for this as well as just showing example code.</p><p>We could improve the solution by adding validation for the files before upload and calculating the upload speed. We’re also not handling errors well.</p><p>We could use redux with Thunks, Sagas or Epics for larger applications rather than a view state service</p><p>The components could also be split into smart and dumb components where the smart component gets the data and calls functions on the view state services and the dumb component, which use props, display the data.</p><p>You can also see a working example of the solution <a href="https://stottle-blob-storage-react.azurewebsites.net/">here</a>. Apologies for the lack of styling.</p><p>Please let me know if you have any comments or suggestions about the article below, but please raise any code issues on the Github repo</p><p><a href="https://github.com/stottle-uk/stottle-react-blob-storage">stottle-uk/stottle-react-blob-storage</a></p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=34f37805fdfc" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Upload to Azure Blob Storage with Angular 8]]></title>
            <link>https://javascript.plainenglish.io/upload-to-azure-blob-storage-with-angular-8-2ed80dfc6672?source=rss-e7aa2ddd4f0------2</link>
            <guid isPermaLink="false">https://medium.com/p/2ed80dfc6672</guid>
            <category><![CDATA[programming]]></category>
            <category><![CDATA[web-development]]></category>
            <category><![CDATA[azure]]></category>
            <category><![CDATA[angular]]></category>
            <category><![CDATA[javascript]]></category>
            <dc:creator><![CDATA[Stuart Tottle]]></dc:creator>
            <pubDate>Wed, 06 Nov 2019 15:19:31 GMT</pubDate>
            <atom:updated>2019-11-14T17:05:35.097Z</atom:updated>
            <content:encoded><![CDATA[<h4>How to upload multiple files to blob storage in a browser with a <em>Shared Access Signature</em> (SAS) token generated from your back-end.</h4><blockquote>Note: This is an update to my earlier article which was using an older version of the Azure Storage js libraries. <a href="https://medium.com/@stuarttottle/upload-to-azure-blob-storage-with-angular-7977e979496a">https://medium.com/@stuarttottle/upload-to-azure-blob-storage-with-angular-7977e979496a</a></blockquote><p>We’ll use Angular 8 and the <a href="https://www.npmjs.com/package/@azure/storage-blob">@azure/storage-blob</a> library to upload the files.</p><p>The final code is on <a href="https://github.com/stottle-uk/stottle-angular-blob-storage">Github</a> which also contains examples on listing containers, blob items and deleting and downloading blob items.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*cWjUUKOJ9Hpjw-gV.png" /></figure><p>We’ll go over</p><ul><li>Creating a component to select and upload files</li><li>Creating a service to manage view state for the uploads</li><li>Securing the upload to Blob Storage with a SAS token</li><li>Creating a service to wrap the uploadBrowserData method in the @azure/storage-blob library to upload a file to Blob Storage</li><li>Creating a component to display upload progress</li></ul><h3>Create File Upload Component</h3><p>The InputFileComponent component allows the user to select one or more files to upload</p><p>We’ll cover</p><ol><li>Selecting one or more files to upload</li><li>Calling the method on the view state service to start the upload</li></ol><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/6c207853dc8bbe0c1f4797997e6a8647/href">https://medium.com/media/6c207853dc8bbe0c1f4797997e6a8647/href</a></iframe><h4><strong>What’s happening?</strong></h4><p>We’ve hidden the input and the file dialogue is opened with the button. The uploadItems method is called on the BlobUploadsViewStateService when the user selects files. We could add some validation here, but to me, it makes more sense to validate in the view state service.</p><h3>Create uploads view state service</h3><p>The BlobUploadsViewStateService service manages the shared view state for the components. I’m quite familiar with NGRX and redux patterns so I’ve created a service into which you can supply items to trigger actions and have observables listening for changes. It also means we can keep the business logic out of the components and the components will generally have a single responsibility.</p><p>We’ll cover</p><ol><li>Listing to an observable to trigger uploads</li><li>Getting a SAS token</li><li>Uploading a file to blob storage</li><li>Keeping a list of all upload progress in the view state</li></ol><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/52f4adf94263b0c8d338ce8007c229d1/href">https://medium.com/media/52f4adf94263b0c8d338ce8007c229d1/href</a></iframe><h4>What’s happening?</h4><p>The public uploadItems method accepts a list of files and calls the next method on the uploadQueueInner$ subject. The uploadQueue$ getter is listening to the subject as an observable and will emit each file in the files list as a separate item. This is one place the files could be validated.</p><p>The uploadedItems$ property is listening to the uploadQueue$ and will call the uploadFile method in the service for each file item emitted. Something will need to subscribe to the uploadedItems$ for uploads to start and display upload progress (we’ll cover this below in the upload progress component)</p><p>The uploadFile method gets the latest SAS token and calls the uploadToBlobStorage on the Blob Storage Wrapper Service with the token and file details (we’ll cover this below).</p><p>The uploadToBlobStorage method returns an observable that emits the loadedBtyes each time it changes and can be used to track upload progress.</p><p>We then map the upload response to a percentage in the mapUploadResponse method and include extra detail. The method also has the startWith operator so any subscribers will be notified as soon as the upload starts rather than waiting for progress to be emitted.</p><p>We then call the finalise method when the upload is complete to refresh the items in the blob container.</p><p>The mapped response from the uploadFile method is then piped into a custom scan operator function to reduce the emitted values into an array. This allows us to store all uploads in progress and add further uploads when uploads are already in progress.</p><h3>Secure the upload with a SAS token</h3><p>The service above calls a method to get a SAS before every upload from a service. The method in this code example returns a hard codes SAS token I generated in the Azure portal, but in the real world, you would call an API to generate and return the SAS token. Here is a basic example in C# using the Azure.Storage.Blobs (v12.0.0) package to generate an Account SAS which can be used for many operations. You can also create SAS tokens for specific blob items or containers when you want/need to be more granular.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/934be821ac51801bc69e0a0c7f491e53/href">https://medium.com/media/934be821ac51801bc69e0a0c7f491e53/href</a></iframe><h3>Wrap the uploadBrowserData method in the @azure/storage-blob library</h3><p>We wrap the @azure/storage-blob library to return observables rather than promises as it works well when emitting progress events.</p><p>We’ll cover</p><ol><li>Creating an injection token which gets the blobServiceClient from the @azure/storage-blob library to make our service testable</li><li>Calling the uploadBrowserData method and returning an observable of the loadedBytes</li></ol><p>Here is a snippet from the <a href="https://github.com/stottle-uk/stottle-angular-blob-storage/blob/master/src/app/azure-storage/services/blob-storage.service.ts">full service</a></p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/fb426770879456d7b7667370ab5536bc/href">https://medium.com/media/fb426770879456d7b7667370ab5536bc/href</a></iframe><h4>What’s happening?</h4><p>The uploadToBlobStorage method in the wrapper service accepts the file to be uploaded and an object with the SAS token. It calls a method which will use the injected token service to return the blobServiceClient which was created using a connection string.</p><p>We then pass the BlockBlobClient created using the blobServiceClient and the file into the uploadFile method which wraps the uploadBrowserData method. We listen to the onProgress events and emit the value each time the progress changes. We then emit the file size and complete the observable when the upload completes.</p><h3>Create a component to display upload progress</h3><p>In this code example, the view state services manage the shared data and the components display the data. This good practice allows us to separate the file input and upload progress components and keeps our components small and have fewer responsibilities (hopefully just one).</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/a0d64ebeff1c6df5a97703820d48101b/href">https://medium.com/media/a0d64ebeff1c6df5a97703820d48101b/href</a></iframe><h4>What’s happening?</h4><p>The uploads$ property is assigned the value from the uploadedItems$ property on the BlobUploadsViewStateService service we referenced above.</p><p>We then subscribe to the observable using the async pipe and display each item in the array.</p><h3>Conclusion</h3><p>This is one way the upload to Azure blob storage could be implemented and I’ve attempted to demonstrate a basic architecture for this as well as just showing example code.</p><p>We could improve the solution by adding validation for the files before upload and calculating the upload speed. We’re also not handling errors well.</p><p>We could use NGRX with effects and selectors for larger applications rather than a view state service</p><p>The components could also be split into smart and dumb components where the smart component gets the data and calls functions on the view state services and the dumb component, which has Inputs and Outputs, display the data.</p><p>You can also see a working example of the solution <a href="https://stottle-blob-storage-angular.azurewebsites.net/">here</a>. Apologies for the lack of styling.</p><p>Please let me know if you have any comments or suggestions about the article below, but please raise any code issues on the Github repo</p><p><a href="https://github.com/stottle-uk/stottle-angular-blob-storage">stottle-uk/stottle-angular-blob-storage</a></p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=2ed80dfc6672" width="1" height="1" alt=""><hr><p><a href="https://javascript.plainenglish.io/upload-to-azure-blob-storage-with-angular-8-2ed80dfc6672">Upload to Azure Blob Storage with Angular 8</a> was originally published in <a href="https://javascript.plainenglish.io/">JavaScript in Plain English</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[My experience with designers from a developer’s point of view.]]></title>
            <link>https://stuarttottle.medium.com/my-experience-with-designers-from-a-developers-point-of-view-afea13003068?source=rss-e7aa2ddd4f0------2</link>
            <guid isPermaLink="false">https://medium.com/p/afea13003068</guid>
            <category><![CDATA[software-development]]></category>
            <category><![CDATA[style-guides]]></category>
            <category><![CDATA[software-design-patterns]]></category>
            <category><![CDATA[agile-development]]></category>
            <category><![CDATA[scrum-agile]]></category>
            <dc:creator><![CDATA[Stuart Tottle]]></dc:creator>
            <pubDate>Thu, 10 Oct 2019 12:51:45 GMT</pubDate>
            <atom:updated>2019-10-10T12:51:45.480Z</atom:updated>
            <content:encoded><![CDATA[<p>I have been working in Frontend Web development with many companies for many years and I believe UI and UX designers are not involved in the development process as much as I think they should be.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*vkxfb-CmRy8F5ui8N11FSg.png" /></figure><p>I’ve been pleased with the architecture of solutions on which I work as I understand Component Structure, Client State, Testing etc, but I’m often left disappointed by the CSS and I feel more understanding and support from designers will help.</p><p>The following is my opinion from my own experiences working with designers. I have worked with some good designers who understand what developers need, but there are many more who do not (and vice versa).</p><p>I’ve grouped UX and UI Designers into the same ‘designers’ term even though they are different disciplines as I believe we all need to find a better way of working together.</p><h3>The Problem</h3><p>How much involvement should designers have in the development process? I have an opinion, but I’d first like to ask the following, slightly loaded, questions which I think will be answered differently depending on role and experience.</p><ul><li>Are designers required to have a good understanding of web standards and technologies, the difference between a browser and a native app and the constraints of a browser?</li><li>Should designers attend stand-ups and regular Scrum meetings and are they often only represented by Product Owners or Business Analysts who only end up relaying questions and feedback?</li><li>Should designers provide developers with detailed designs of each page at the different breakpoints and include an extra design for each popover and modal which might be needed on each page?</li><li>Should designers create a style guide with wireframe mock-ups that developers can use to create a CSS framework with similar naming conventions to the style guide?</li><li>Should designers consider the developers skill level and experience?</li><li>Do designers need to understand CSS and how Flexbox and/or Grid work?</li><li>Should designers have an understanding of open source <a href="https://en.wikipedia.org/wiki/CSS_framework">CSS frameworks</a>* and how to utilise their components and elements, but with a modified design?</li><li>Do designers understand how the CSS frameworks are documented and therefore make them arguably easy to use?</li><li>Would incorporating an existing CSS framework into the designs save time and money on projects as there are components already written with extensive documentation for the JS library/framework* in which your application is written?</li><li>When should we style entire applications without using a CSS framework?</li><li>Is there a stigma to using a CSS framework?</li><li>Should designers think about how their designs will be <a href="https://en.wikipedia.org/wiki/Software_testing">tested</a> and whether those tests could be <a href="https://www.cypress.io/">automated</a>?</li><li>How can we make the application easier to use for users with accessibility requirements?</li></ul><p>*CSS Frameworks — <a href="https://getbootstrap.com/docs/4.0/getting-started/introduction/">Bootstrap</a>, <a href="https://material.io/">Material</a>, <a href="https://foundation.zurb.com/">Foundation</a>, <a href="https://bulma.io/">Bulma</a> etc</p><p>*JS Libraries/Frameworks — <a href="https://reactjs.org/">Reactjs</a>, <a href="https://angular.io/">Angular</a>, <a href="https://vuejs.org/">Vue</a> etc</p><h3>An Example</h3><p>I don’t know the answers to the above questions, but I know developers will normally want to support and understand the designer’s UX/UI vision so they can reduce complexity. In my experience, designers are often not directly involved in the development process and rarely speak with the actual developer who will implement their designs. The design discussions are often held between marketing and the product owner who then passes on the designers’ ideas in Scrum meetings and backlog tickets.</p><p>Would it help if designers were personally required to present their designs to the development team to gain feedback on how they could be implemented and maintained? The following are two made-up stories where I hope to emphasise the problem (They are using an existing API for data)</p><h4>A Tragedy</h4><p>The product owner organised an extra meeting to present the 40 separate designs of the new 5-page admin application to the development team. Despite the Modals never being in the same place and size on 2 pages, one of the developers noted the designs use the same breakpoints and column layout as Bootstrap and used what looked like a navbar, input groups, modals and cards. A meeting action was created to ask the designer to investigate whether the existing bootstrap components and elements could be styled to meet their vision.</p><p>The designer hates Bootstrap, they’ve heard other designers complain about its dull look and how all sites that use bootstrap look the same — they said no and the developers used the 40 designs which were loosely related to the user stories and didn’t have a clear vision on the designer’s intent. The developers probably then either</p><ol><li>Styled each page/component individually and created something hard to test and time-consuming to maintain</li><li>Planned a framework without the designer’s collaboration that ended up not working when the designs went off in a different direction or had too many variations on similar elements and/or the development team changed.</li></ol><p>The designer was never available to answer questions and the stories were carried over several sprints as testers sought clarification and further development was required.</p><h4>A Dream.</h4><p>The product owner organised a workshop for the designers to present their rough sketches for the initial 5 pages of the new content sharing platform. The product owner also provided User Stories with Acceptance Criteria that contained no implementation detail for each sketch.</p><p>During the meeting, the designer asked the development team,</p><ul><li>What is the best way to implement the designs?</li><li>Can we work together on a style guide?</li><li>Do the designs work in both native apps and modern evergreen browsers?</li><li>Can we create a design that gives us what we want, but makes the most of the resources we have available?</li><li>How much compromise will be required on styling if it means we will save time and money and boost performance?</li><li>How can we make it Testable and Accessible?</li></ul><p>The developers and the designers looked at Bootstrap together and reviewed the documentation that demonstrated how <a href="https://sass-lang.com/documentation/syntax">SCSS</a> can be used to update the standard look. The designer wasn’t overly keen on being constrained by a framework but understood the developer’s point of view and was willing to learn something new. They created a responsive prototype together in a short amount of time that didn’t look like Bootstrap and worked on a screen reader.</p><p>After the workshop, the designer read the online documentation and began work on the wireframes and style guide. The backlog tickets were added to a sprint during which the designer was made available for regular contact and worked with the developers to update the style guide whilst the features were being developed.</p><p>The User Stories were completed in good time as the major blockers on most stories were working closely together and testers had fewer queries with the designs. The result was an optimized fully tested reusable framework with e2e tests that met the designers’ vision and complied with accessibility requirements.</p><p>The developers referred to the vast array of online documentation and needed only to update SCSS variables to meet the design requirements and created documentation for the few extra custom components.</p><p>The designer isn’t required as much in further development phases and is freed up to work on other projects as the developers can follow the style guide and wireframe mock-ups.</p><p>*I’ve mentioned Bootstrap above, I don’t have a preference and it’s only because it is the most used Framework. it’s also worth noting that developers need to understand the limitation of using JS libraries that wrap CSS libraries as they could have limited touch support on mobile devices.</p><h3>Change?</h3><p>I’m aware the two stories above are tinged with bias, brevity and fantasy and in reality, most projects fit in-between those two extremes, but I hope Designers and Developers find a way to work closer. They often represent different parts of the business and might be in other buildings, countries or payrolls so conferencing tools that allow screen sharing is must to aid collaboration.</p><p>I’ve worked on projects where designers did attend Scrum meetings but didn’t empathise with how the developer would implement their designs and found it difficult to find time to answer questions as they had their deadline for styling the next feature. I’ve worked on other projects where the designer was a member of the development team and contributed to code. Their changes were reviewed by other developers and I feel this was the most effective setup. The designer improved their JavaScript skills and the developers understood the designer’s intent.</p><p>Overall, we need to better understand the problems each team is trying to solve whether it is UX or implementation and learn a bit more about each other’s craft. Developers are learning and using frameworks and libraries to speed up the development of repeating functionality, but I feel like the approach to design isn’t evolving at the same pace.</p><p>A few points to summarise</p><ul><li>Create a <a href="http://styleguides.io/">Style Guide / Pattern Library</a>— it helps</li><li>Work together to refine wireframes and the style guide</li><li>Include the designers in the development process and Scrum teams and budget for it</li><li>Do not design too much without first getting the developers involved for feedback.</li><li>Allow designers to be available for regular short focused screen sharing meetings to discuss progress when styling a feature.</li><li>Understand how the big CSS frameworks are documented and can be used.</li><li>Investigate whether component and elements in an existing CSS framework can be styled to match the designers’ vision.</li><li>Think about how the designs can be tested.</li><li>Think mobile-first and how elements move and change through different breakpoints as the screen gets larger.</li><li>Keep in mind a CSS framework can be removed when there is a style guide if it seems like too much bloat as only the CSS classes need to be re-implemented.</li><li>And most of all… Keep the designs simple</li></ul><p>User design is arguably more important than developer code as a poorly engineered application with a good UX and is better for the user then a frustrating UI with a fantasticality engineered codebase. But… system and code maintainability are really important when you want to make further changes so, work together, create a design framework and be prepared.</p><h3>Further Reading</h3><p><a href="https://css-tricks.com/the-great-divide/">https://css-tricks.com/the-great-divide/</a></p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=afea13003068" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Angular — Authentication with Auth0 and NGRX]]></title>
            <link>https://stuarttottle.medium.com/angular-authentication-with-auth0-and-ngrx-e22228b04b3?source=rss-e7aa2ddd4f0------2</link>
            <guid isPermaLink="false">https://medium.com/p/e22228b04b3</guid>
            <category><![CDATA[authentication]]></category>
            <category><![CDATA[javascript]]></category>
            <category><![CDATA[angular]]></category>
            <category><![CDATA[ngrx]]></category>
            <category><![CDATA[auth0]]></category>
            <dc:creator><![CDATA[Stuart Tottle]]></dc:creator>
            <pubDate>Sun, 04 Nov 2018 20:27:12 GMT</pubDate>
            <atom:updated>2018-11-11T12:54:54.538Z</atom:updated>
            <content:encoded><![CDATA[<h3>Angular — Authentication with Auth0 and NGRX</h3><p>My interpretation of how auth0 can be integrated with NGRX in an Angular Application.</p><p>I’ve implemented Auth0 in several Angular applications over the years and wanted to document a way of achieving this.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/755/1*-KKAIlTAj_YvF_mFWjiOKQ.png" /></figure><h3>Overview</h3><p>I’ve created an Angular module which could be imported into any angular application that wraps the Auth0 library into an Angular Service and stores authentication details in NGRX.</p><p>This article is structured as follows:</p><ol><li>Using the <a href="https://auth0.github.io/auth0.js/global.html">auth0-js</a> library to authenticate a user</li><li>Storing, renewing and retrieving the access token in the NGRX store</li><li>Router guards using data from the NGRX store</li><li>HTTP interceptors to add the bearer token to HTTP requests</li><li>Redux dev tools example</li></ol><p>Final code is on <a href="https://github.com/stottle-uk/platform/tree/master/libs/ngx-auth0-wrapper-ngrx">GitHub</a></p><p>I’ve also created an <a href="https://www.npmjs.com/package/@stottle-platform/ngx-auth0-wrapper-ngrx">NPM package</a></p><h3>1. Using the auth0-js library to authenticate a user</h3><p>I’m using an <a href="https://www.npmjs.com/package/@stottle-platform/ngx-auth0-wrapper">npm package</a> that wraps selected methods from the auth0-js library and returns values from methods as an observable.</p><p>It makes use of the <a href="https://auth0.github.io/auth0.js/global.html#authorize">authorize</a> method that redirects the user to the Auth0 <a href="https://auth0.com/docs/hosted-pages/login">hosted login</a> page, which can be customised to suit the layout and style of your application. The package handles the authorisation callback and emits the authentication information (decoded hash) as an observable.</p><p>The library also stores a redirect URL in local storage which can be retrieved when the user has returned to your site to redirect the user after login.</p><h3>2. Storing, renewing and retrieving the access token in the NGRX store</h3><p>I’ve attempted to split the store into small collections (actions, effects and reducers) that have a responsibility for</p><ul><li>Showing the login page, handling authorisation and logout</li><li>Obtaining user information</li><li>Renewing access token (check session)</li><li>Checking users’ authentication status and populating the NGRX store</li><li>Resetting password</li></ul><h4>Showing the login page, handling authorisation and logout</h4><p><strong>Aim</strong>: to show the login page and how to handle the authentication callback to add the access token and the time it will expire to the NGRX store (and local storage) - also to log the user out to revoke their access token.</p><ul><li><em>Package link:</em> <a href="https://github.com/stottle-uk/platform/tree/master/libs/ngx-auth0-wrapper-ngrx/src/lib/%2Bstate/authorization">authorization</a></li><li><em>Auth0 link:</em> <a href="https://auth0.com/docs/libraries/auth0js/v9#webauth-authorize-">authorize</a></li></ul><p>Dispatch the Authorize action to display the sign-up or login form. The action has two parameters for the redirectUrl (where do you want to navigate the user after they have been authorised) and the <a href="https://auth0.github.io/auth0.js/global.html#authorize">auth0 authorize</a> options to display the sign-up/login form and other items. This will take the user to the hosted login form and return the user to the specified callback page after they have entered the correct details.</p><p>The callback component dispatches the AthenticationComplete action which handles the Auth0 <a href="https://auth0.github.io/auth0.js/global.html#parseHash">authorization callback</a> and dispatches the AuthenticationSuccess action to save the Authentication Details in the NGRX store (including the access token).</p><p>You could also listen to the AuthenticationSuccess action in your application effects and use the payload to perform various actions including</p><ul><li>Redirecting the user when they return to your application (<a href="https://github.com/stottle-uk/platform/blob/master/apps/web/src/app/users/%2Bstate/users.effects.ts">example</a>)</li><li>Getting user data from your own API</li><li>Connecting to a WebSocket.</li></ul><p>Use the selectAuthenticationData or selectIsAuthenticated selectors to retrieve authentication details from the NGRX store (including the access token).</p><blockquote><strong>Error:</strong> You can handle errors in your application by listening to the AuthenticationError action in your effects and/or using the selectAuthenticationError selector.</blockquote><p>To log the user out, dispatch the Logout action to revoke their access token and clear the NGRX store and local storage.</p><h4>Obtaining user information</h4><p><strong>Aim:</strong> to obtain user information and claims from Auth0 after the user is authenticated.</p><ul><li><em>Package link:</em> <a href="https://github.com/stottle-uk/platform/tree/master/libs/ngx-auth0-wrapper-ngrx/src/lib/%2Bstate/user-info">user-info</a></li><li><em>Auth0 link:</em> <a href="https://auth0.com/docs/libraries/auth0js/v9#extract-the-authresult-and-get-user-info">userInfo</a></li></ul><p>The GetUserInfoStart action is dispatched when the AuthenticationSuccess action is dispatched, and it will obtain information and claims about the logged in user based on the requested scopes from <a href="https://auth0.github.io/auth0.js/global.html#userInfo">Auth0</a>. You shouldn’t need to dispatch this from within your application.</p><p>The users’ information can be retrieved from the store using the selectUserInfo selector.</p><h4>Renewing Access Token (check session)</h4><p><strong>Aim:</strong> to renew the access token at regular intervals to ensure the user has not logged out on another device or if it is about to expire.</p><ul><li><em>Package link</em>: <a href="https://github.com/stottle-uk/platform/tree/master/libs/ngx-auth0-wrapper-ngrx/src/lib/%2Bstate/check-session">check-session</a></li><li><em>Auth0 link</em>: <a href="https://auth0.com/docs/libraries/auth0js/v9#using-checksession-to-acquire-new-tokens">checkSession</a></li></ul><p>The ScheduleSessionCheck action is dispatched when the AuthenticationSuccess action is dispatched and starts a timer to perform a session check either just before the access token is due to expire or at an interval (set by options when importing the module)</p><p>Check the session at regular intervals, as a user could be accessing your application from multiple devices or you could have multiple applications that use the same user account.</p><h4>Checking users’ authentication status and populating the store</h4><p><strong>Aim</strong>: to check local storage for valid authentication information and renew the access token when a user returns to your site.</p><ul><li><em>Package link:</em> <a href="https://github.com/stottle-uk/platform/tree/master/libs/ngx-auth0-wrapper-ngrx/src/lib/%2Bstate/authentication">authentication</a></li></ul><p>Dispatch the CheckAuthenticationStatus action in the app.component to check local storage for an access token and whether it has expired.</p><p>The UserIsAuthenticated action is dispatched if the user’s access token is valid, and this will dispatch the CheckSessionStart action to renew the user’s access token to ensure the NGRX store has the latest authentication details (and local storage).</p><p>The UserIsNotAuthenticated action is dispatched when the user is not authenticated to allow your application to dispatch further actions if required.</p><h4>Changing a user’s password</h4><p><strong>Aim:</strong> to ask the user for their email address so the user can be sent an email with a link to change their password</p><ul><li><em>Package link:</em> <a href="https://github.com/stottle-uk/platform/tree/master/libs/ngx-auth0-wrapper-ngrx/src/lib/%2Bstate/change-password">change-password</a></li><li><em>Auth0 link:</em> <a href="https://auth0.com/docs/libraries/auth0js/v9#password-reset-requests">changePassword</a></li></ul><p>Dispatch the ChangePasswordStart action with the relevant options to send a change password email to the user using <a href="https://auth0.github.io/auth0.js/global.html#changePassword">changePassword</a> in the Auth0-js library. The response is saved in the NGRX store and can be retrieved using the selectChangePasswordResponse selector.</p><h3>3. Route Guard</h3><p>The router guard checks the NGRX store as to whether the user is authenticated. It will also dispatch the Authorize action to show the login form if the user is not authenticated and save the Url the user was trying to access so the user can be redirected after login.</p><p><em>Package Link:</em> <a href="https://github.com/stottle-uk/platform/blob/master/libs/ngx-auth0-wrapper-ngrx/src/lib/services/auth-guard.service.ts">auth-guard</a></p><h3>4. HTTP Interceptor</h3><p>The HTTP interceptor will intercept all HTTP request to check if the user is authenticated and add the authorisation header with the bearer access token from the NGRX store.</p><p><em>Package Link:</em> <a href="https://github.com/stottle-uk/platform/blob/master/libs/ngx-auth0-wrapper-ngrx/src/lib/services/auth-intercepter.service.ts">auth-interceptor</a></p><h3>5. Redux dev tools example</h3><p><a href="https://www.youtube.com/watch?v=JmnsEvoy-gY">Action Hygiene</a> is important as the redux dev tools should tell a story to other developers of what is happening in your application. Below are some screen shots of the redux dev tools for when a user</p><ul><li>Is not authenticated</li><li>Has just logged in</li><li>Has returned to the site and has a valid access token in Local Storage</li></ul><h4>Is not authenticated</h4><p>The application checks the store for a valid access token and clears local storage if it is not valid.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/368/1*33XnlLGT84qq6rhmk2lmNQ.png" /><figcaption>User not authenticated</figcaption></figure><h4>Has just logged in</h4><p>The application still checks local storage when the user has returned to your site, so it still thinks the user is not authenticated, but the callback component then dispatches the AuthenticationComplete action and the user’s authentication details are stored in NGRX (and local storage), a session check is scheduled and the user info is retrieved. The application also redirects the user to the route they were trying to access before they logged in.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/353/1*wtaETNmiztyXpJBci2WVpA.png" /><figcaption>After login</figcaption></figure><h4>Is returning to the site and has a valid access token in Local Storage</h4><p>The application finds a valid access token and dispatches a session check to update the access token and obtain the user info.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/350/1*T9cQw2X1wkBQas7KPNBXlw.png" /><figcaption>Returning user</figcaption></figure><h3>Conclusion</h3><p>This is my interpretation of how a library could be created to manage authentication in Angular, so please let me know if you have any questions, comments or observations about the article, but raise code issues on the <a href="https://github.com/stottle-uk/platform">GitHub repo</a>.</p><p>The package I have created is available on npm (<a href="https://www.npmjs.com/package/@stottle-platform/ngx-auth0-wrapper-ngrx">@stottle-platform/ngx-auth-wrapper-ngrx</a>), and I have implemented the package in my own application (<a href="https://stottle.co.uk/">stottle.co.uk</a>), so feel free to browse the code repo on <a href="https://github.com/stottle-uk/platform">GitHub</a>.</p><p>There is also an NGRX example from <a href="https://auth0.com/blog/ngrx-authentication-tutorial/">Auth0</a> from which I drew some inspiration.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=e22228b04b3" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Upload to Azure Blob Storage with Angular]]></title>
            <link>https://stuarttottle.medium.com/upload-to-azure-blob-storage-with-angular-7977e979496a?source=rss-e7aa2ddd4f0------2</link>
            <guid isPermaLink="false">https://medium.com/p/7977e979496a</guid>
            <category><![CDATA[angular]]></category>
            <category><![CDATA[angular-cli]]></category>
            <category><![CDATA[cloud-storage]]></category>
            <category><![CDATA[azure-services]]></category>
            <category><![CDATA[storage-solutions]]></category>
            <dc:creator><![CDATA[Stuart Tottle]]></dc:creator>
            <pubDate>Sun, 04 Mar 2018 09:10:58 GMT</pubDate>
            <atom:updated>2019-11-08T15:00:17.047Z</atom:updated>
            <content:encoded><![CDATA[<p>Upload multiple files to blob storage and report progress using Angular with a <em>Shared Access Signature</em> (SAS) token generated from your back-end.</p><blockquote><strong>Update 2019–11–05: I’ve created a new article that uses Angular &amp; and the newer Azure Blob Storage NPM package @azure/storage-blob. You can see it </strong><a href="https://medium.com/@stuarttottle/upload-to-azure-blob-storage-with-angular-8-2ed80dfc6672"><strong>here</strong></a></blockquote><p><a href="https://medium.com/@stuarttottle/upload-to-azure-blob-storage-with-angular-8-2ed80dfc6672">Upload to Azure Blob Storage with Angular 8</a></p><p>We’ll go over</p><ul><li>Creating an Angular project using the Angular-Cli</li><li>Creating an Angular service to upload a file to Blob Storage with tests</li><li>Update app component to upload files and display upload progress</li><li>Securing the upload to Blob Storage with a SAS token</li></ul><p>Final code is <a href="https://github.com/stottle-uk/stottle-angular-blob-storage-upload">here</a></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*LdpYFO2NPOXE1XYlFQZGNQ.png" /></figure><h3>Create the Angular solution</h3><p>Use the Angular-Cli to create a new Angular project and the Blob Storage service.</p><pre>npm install -g @angular/cli</pre><pre>ng new stottle-angular-blob-storage-upload</pre><pre>cd ./stottle-angular-blob-storage-upload</pre><pre>ng g service azure-storage/blobStorage -m app.module.ts</pre><h4>Add Azure Storage JS Library Files</h4><p>Download the files from: <a href="https://aka.ms/downloadazurestoragejs">https://aka.ms/downloadazurestoragejs</a></p><p>We are using version `2.10.100` for this example.</p><p>There are several files in the download but we just need to add the azure-storage.blob.js file to the assets directory in your Angular-Cli project. Also, add a reference to the script in angular.json</p><pre>“scripts”: [ <br>    “./assets/azure-storage/azure-storage.blob.js” <br>]</pre><h3>Create the Blob Upload Service</h3><p>We’ll show examples for</p><ol><li>Creating interfaces for the azure-storage.blob.js script</li><li>Updating the blob-storage.service.ts to upload the files and report progress</li><li>Creating a stub of azure-storage.blob.js script to mock the upload progress for our tests</li><li>Updating blob-storage.service.spec.ts to use our stub and test the service</li></ol><h4>1. Interfaces</h4><p>Create a file (eg azureStorage.ts) in the same directory as the blob storage service to contain the Interfaces for the azure-storage.blob.js script. There is also an azure-storage npm package with typings etc which I am sure could be used.</p><p>We also create an injection token on line 38 so we can create a stub for azure-storage.blob.js in our tests (example below).</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/05911fb3ef6f4d20eee1255d739eea96/href">https://medium.com/media/05911fb3ef6f4d20eee1255d739eea96/href</a></iframe><h4>2. Blob Storage Service</h4><p>Update blob-storage.service.ts with the following</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/23222b650fd00fefb8b6510f6cd9fda8/href">https://medium.com/media/23222b650fd00fefb8b6510f6cd9fda8/href</a></iframe><p>The only public method uploadToBlobStorage returns an observable of a number that represents the completed percent of the upload progress.</p><p>The implementation I am using it for requires a complete percentage of 100 so Iworked around this on line 55 as the progress could return 100 before the complete callback on line 44.</p><p>We also return a start value of 0 on line 48 so any subscriptions to the upload progress will have an initial value of 0 instead of waiting for spreed summary progress or complete callback to emit a value.</p><h4>3. Create stub for testing</h4><p>Create a file (eg blob-stroage-stub.ts) for the stub of the azure-storage.blob.js script. We use our interfaces created in step 1 and use rxjs to mock the upload progress. We also export an uploadProgressStub on line 5 to compare the progress emitted from our service to the current progress in the stub.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/da5bd96e0e0a0112eff8e5044f63f399/href">https://medium.com/media/da5bd96e0e0a0112eff8e5044f63f399/href</a></iframe><h4>4. Test the service</h4><p>Update blob-storage.service.spec.ts file to test our service. We provide our injection token on line 14 and set the value as our stub on line 15.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/d28cac3c02c2a57fbf889131f41d1e46/href">https://medium.com/media/d28cac3c02c2a57fbf889131f41d1e46/href</a></iframe><h3>Create input in app component</h3><p>Add aonFileChange method to app.component.ts to handle the change event of a file input and inject the BlobStorageService as a dependency.</p><p>On line 38 we</p><ol><li>Create an observable from our selected files to emit each file one at a time.</li><li>Map the file to an observable of the upload progress. The uploadFile method uses the blob storage service to upload the file and return an observable of the upload progress.</li><li>Combine all the mapped observable’s to return an observable with an array of items which represent our upload progress</li></ol><p>Also update the template to include</p><ul><li>a file input which triggers a function on change and include the multiple attribute to allow multiple files to be selected for upload.</li><li>the upload progress obserable</li></ul><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/26d70c0042c6b7e04ebc6d241cdfad6a/href">https://medium.com/media/26d70c0042c6b7e04ebc6d241cdfad6a/href</a></iframe><h3>Update app.module</h3><p>Use the injection token to provide the azure-storage.blob.js script and declare the script on line 7</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/d8414d3740903f33edccf1e641d3a8c9/href">https://medium.com/media/d8414d3740903f33edccf1e641d3a8c9/href</a></iframe><h3><em>Shared Access Signature</em> (SAS) Token</h3><p>We have hard coded the SAS token and location in the onFileChange method as I’m using the Azure Storage Emulator installed locally and I’ve generated the SAS Token using the Azure Storage Explorer (right click on the container to generate), but it would make much more sense to integrate with an API which requires authorisation to supply a</p><ul><li>SAS Token with a limited life span</li><li>Url of the storage account <em>“http://&lt;accountname&gt;.blob.core.windows.net”</em></li><li>Name of the container to which the file will be uploaded</li></ul><figure><img alt="" src="https://cdn-images-1.medium.com/max/450/0*faTXnPpjB8ttJlZB." /></figure><h4>Cors</h4><p>Don’t forget to configure CORS in your emulator or the azure portal.</p><h3>Conclusion</h3><p>We could improve the solution by validating the file type, handling exceptions during the upload and include average upload speed as the `speedSummary` also returns other useful information which is available in their API docs</p><p>We could also add the response to the observable returned from the upload method rather than 100 to confirm the status of the upload.</p><p>We’re calling the done() method to let jasmine know the test has finished. We did try using fakeAsync, but ran into error stating Error: 1 timer(s) still in the queue. My brief research seemed to point to an issue with using interval in rxjs and i’m hoping anyone reading this article can explain to me why and if there is a better way to create the stub.</p><p>I also found another NPM package (<a href="https://github.com/Gullfaxi171/angular-azure-blob-service"><strong>angular-azure-blob-service</strong></a>) which worked well and uses the HttpClient in Angular to upload the file in blocks.</p><h4>Links</h4><ul><li><a href="https://dmrelease.blob.core.windows.net/azurestoragejssample/samples/sample-blob.html">Azure Storage JavaScript Client Library Sample for Blob Operations</a></li><li><a href="https://azure.microsoft.com/en-gb/blog/new-azure-storage-javascript-client-library-for-browsers-preview/">New Azure Storage JavaScript client library for browsers - Preview | Blog | Microsoft Azure</a></li><li><a href="https://github.com/Gullfaxi171/angular-azure-blob-service">Gullfaxi171/angular-azure-blob-service</a></li><li><a href="https://github.com/Azure/azure-storage-node/blob/master/browser/README.md">Azure/azure-storage-node</a></li></ul><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=7977e979496a" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[SecurionPay Subscriptions in Node Js]]></title>
            <link>https://stuarttottle.medium.com/securionpay-subscriptions-in-node-js-ff2c4521701f?source=rss-e7aa2ddd4f0------2</link>
            <guid isPermaLink="false">https://medium.com/p/ff2c4521701f</guid>
            <category><![CDATA[subscription]]></category>
            <category><![CDATA[securion-pay]]></category>
            <category><![CDATA[nodejs]]></category>
            <category><![CDATA[javascript]]></category>
            <dc:creator><![CDATA[Stuart Tottle]]></dc:creator>
            <pubDate>Mon, 05 Feb 2018 08:53:35 GMT</pubDate>
            <atom:updated>2018-02-05T09:31:54.258Z</atom:updated>
            <content:encoded><![CDATA[<p><strong>TL;DR </strong>Setup a repeating subscription for a customer using <a href="https://securionpay.com/">Securion Pay</a> in Node Js with their <a href="https://www.npmjs.com/package/securionpay">NPM package</a>.</p><p>Final code is <a href="https://github.com/stottle-uk/stottle-securion-pay">here</a></p><p><em>I am in no way affiliated with Securion Pay, I implemented it in a project.</em></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/740/1*uLvmBlCtpifUTtnmEOFvwQ.jpeg" /></figure><h3>Project setup</h3><p>Create a Securion Pay account and use the Secret Key from the API keys</p><p>I’m using</p><ul><li>Node Js 8.9.4</li><li>Securionpay npm package 1.0.0</li></ul><pre>const securionpay = require(‘securionpay’)(process.env.SECURIONPAY_API_KEY);</pre><h3>Create plan</h3><p>Setup a plan to define the subscription charging details (eg name, amount, interval). Save the returned Plan Id as it is required for creating subscriptions.</p><pre>async createPlan() {<br>  return await securionpay.plans.create({<br>    amount: 2000,<br>    currency: ‘GBP’,<br>    interval: ‘month’,<br>    name: ‘my first plan’<br>  }).then(result =&gt; {<br>    console.log(result);<br>    return result;<br>  });<br>}</pre><h3>Create Customer</h3><p>Create a customer to which the subscription will be associated. The Customer Id from the returned values could be saved against the user in your own users repository as it is required when creating a subscription.</p><pre>async createCustomer() {<br>  return await securionpay.customers.create({<br>    email: ‘<a href="/service/mailto:user@example.com">user@example.com</a>’,<br>    description: ‘User description’<br>  }).then(result =&gt; {<br>    console.log(result);<br>    return result;<br>  });<br>}</pre><h3>Add payment card</h3><p>Add a payment card for the customer as a subscription cannot be created for a customer that does not have an active card. (TODO: Check PCI compliance regarding the card details you store)</p><pre>async createCard(customer) {<br>  return await securionpay.cards.create(customer.id, {<br>    number: ‘4242424242424242’,<br>    expMonth: ‘12’,<br>    expYear: ‘2020’,<br>    cvc: ‘123’,<br>    cardholderName: ‘John Smith’<br>  }).then(result =&gt; {<br>    console.log(result);<br>  });<br>}</pre><h3>Create subscription</h3><p>Create the subscription by supplying the Customer id and Plan id</p><pre>async subscribeToPlan(customer, plan) {<br>  await securionpay.subscriptions.create(customer.id, {<br>    &#39;planId&#39;: plan.id<br>  }).then(result =&gt; {<br>    console.log(result);<br>  });<br>}</pre><h3>Wire it up</h3><p>Add the methods above to a class called `SecurionPayService` and run the following. Check in your Securion Pay dashboard for the new records after running the method.</p><pre>const go = async () =&gt; {<br> const payService = new SecurionPayService();<br> const plan = await payService.createPlan();<br> const customer = await payService.createCustomer();<br> await payService.createCard(customer);<br> await payService.subscribeToPlan(customer, plan);<br>}</pre><pre>go();</pre><h3>Payments — Web hooks</h3><p>Create services to listen to events such as subscription payments and charge statuses — i hope to cover this in a future post.</p><h3>Links</h3><p>The Securion Pay documentation is pretty good</p><ul><li><a href="https://github.com/securionpay/securionpay-node">securionpay/securionpay-node</a></li><li><a href="https://securionpay.com/docs">Getting Started | SecurionPay</a></li><li><a href="https://github.com/stottle-uk/stottle-securion-pay">stottle-uk/stottle-securion-pay</a></li></ul><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=ff2c4521701f" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[ASP.NET Core 2.0 Integration Testing with Identity Server — In Docker]]></title>
            <link>https://stuarttottle.medium.com/asp-net-core-2-0-integration-testing-with-identity-server-in-docker-7a68f407832f?source=rss-e7aa2ddd4f0------2</link>
            <guid isPermaLink="false">https://medium.com/p/7a68f407832f</guid>
            <category><![CDATA[integration-testing]]></category>
            <category><![CDATA[dotnet-core]]></category>
            <category><![CDATA[containers]]></category>
            <category><![CDATA[identity-server]]></category>
            <category><![CDATA[docker]]></category>
            <dc:creator><![CDATA[Stuart Tottle]]></dc:creator>
            <pubDate>Fri, 12 Jan 2018 17:14:38 GMT</pubDate>
            <atom:updated>2018-01-15T11:41:53.655Z</atom:updated>
            <content:encoded><![CDATA[<p><strong>TL;DR</strong> This is the <em>2nd part</em> to <a href="https://medium.com/comparethemarket/asp-net-core-2-0-integration-testing-with-identity-server-7f328c22d969">this</a> post. We will now run an integration test against an API endpoint that requires authentication in docker containers. We will</p><ul><li>Setup environment variables</li><li>Create dockerfiles for Identity Server and Tests</li><li>Create a bash script to run tests in containers</li></ul><p>See the final code <a href="https://github.com/stottle-uk/IntegrationTestingWithIdentityServer/tree/docker">here</a> (on docker branch)</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/928/1*X8lCtfCHbPQ6fwLCUNOAkw.png" /></figure><h3>Update API</h3><p>In the MyApiServer project, update the JWT Bearer Options method to pull in the configuration for the Identity Server from environment variables</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/58ef04923601cf4fee2e1f870a0e9b5f/href">https://medium.com/media/58ef04923601cf4fee2e1f870a0e9b5f/href</a></iframe><h3>Update Identity Server</h3><p>In the MyIdentityServer project, add the dockerfile to</p><ul><li>Restore Nuget packages</li><li>Run Identity Server on port 8002</li></ul><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/15a03eb76ccd6707b0f60ae1c13cc8d0/href">https://medium.com/media/15a03eb76ccd6707b0f60ae1c13cc8d0/href</a></iframe><h3>Update Tests</h3><p>In the MyApiServerTests project, update the constructor in UnitTest1 to pull in the configuration for the Identity Server</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/a7e6f679bb3bcab69ccc9ee116f15bc4/href">https://medium.com/media/a7e6f679bb3bcab69ccc9ee116f15bc4/href</a></iframe><p>And add the dockerfile to</p><ul><li>Restore Nuget packages</li><li>Set Environment Variables</li><li>Run the tests</li></ul><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/7451e68a62edaf6536c61f902cb7ce90/href">https://medium.com/media/7451e68a62edaf6536c61f902cb7ce90/href</a></iframe><h3>Add dockerignore</h3><p>Add .dockerignore in the root of the project (same level as sln file) to exclude folders when building containers</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/7bc7d91557bd0308929650ab29d0852a/href">https://medium.com/media/7bc7d91557bd0308929650ab29d0852a/href</a></iframe><h3>Add bash script to run tests</h3><p>Create tests.sh in the root of the project to build and run the images to execute the tests</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/f2b323141cea52a0c182c63d7c0b1333/href">https://medium.com/media/f2b323141cea52a0c182c63d7c0b1333/href</a></iframe><p>Now run ./tests.sh from a terminal and you should see two passing tests.</p><p>Notes:</p><ul><li>You might need to make the bash script executable chmod +x ./tests.sh</li><li>Bash scripts can be run in Powershell on Windows</li></ul><h3>Conclusion</h3><p>We now have our tests running in containers, but we could still do a few more things which go beyond this post</p><ul><li>Create a docker network in which you can run the containers</li><li>Use docker-compose instead of a bash script</li></ul><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=7a68f407832f" width="1" height="1" alt="">]]></content:encoded>
        </item>
    </channel>
</rss>