Adding an external Microsoft login to IdentityServer4

This article shows how to implement a Microsoft Account as an external provider in an IdentityServer4 project using ASP.NET Core Identity with a SQLite database.

Setting up the App Platform for the Microsoft Account

To setup the app, login using your Microsoft account and open the My Applications link

https://apps.dev.microsoft.com/?mkt=en-gb#/appList

id4-microsoft-apps

Click the Add an app button. Give the application a name and add your email. This app is called microsoft_id4_enrico.

id4-microsoft-apps-registration

After you clicked the create button, you need to generate a new password. Save this somewhere for the application configuration. This will be the client secret when configuring the application.

id4-microsoft-apps-myapp

Now Add a new platform. Choose a Web type.

id4-microsoft-apps-platform

Now add the redirect URL for you application. This will be the https://YOUR_URL/signin-microsoft

id4-microsoft-apps-platform2

Add the Permissions as required

id4-microsoft-apps-permission

id4-microsoft-apps-permission-list

pplication configuration

Note: The samples are at present not updated to ASP.NET Core 2.0

Clone the IdentityServer4 samples and use the 6_AspNetIdentity project from the quickstarts.
Add the Microsoft.AspNetCore.Authentication.MicrosoftAccount package using Nuget as well as the ASP.NET Core Identity and EFCore packages required to the IdentityServer4 server project.

The application uses SQLite with Identity. This is configured in the Startup class in the ConfigureServices method.

services.AddDbContext<ApplicationDbContext>(options =>
       options.UseSqlite(Configuration.GetConnectionString("DefaultConnection")));
 
services.AddIdentity<ApplicationUser, IdentityRole>()
    .AddEntityFrameworkStores<ApplicationDbContext>()
    .AddDefaultTokenProviders()
    .AddIdentityServer();

Now the AddMicrosoftAccount extension method can be use to add the Microsoft Account external provider middleware in the Configure method in the Startup class. The SignInScheme is set to “Identity.External” because the application is using ASP.NET Core Identity. The ClientId is the Id from the app ‘microsoft_id4_damienbod’ which was configured on the my applications website. The ClientSecret is the generated password.

services.AddAuthentication()
     .AddMicrosoftAccount(options => {
          options.ClientId = _clientId;
          options.SignInScheme = "Identity.External";
          options.ClientSecret = _clientSecret;
      });
 
services.AddMvc();
 
...
 
services.AddIdentityServer()
     .AddSigningCredential(cert)
     .AddInMemoryIdentityResources(Config.GetIdentityResources())
     .AddInMemoryApiResources(Config.GetApiResources())
     .AddInMemoryClients(Config.GetClients())
     .AddAspNetIdentity<ApplicationUser>()
     .AddProfileService<IdentityWithAdditionalClaimsProfileService>();

And the Configure method also needs to be configured correctly.

If you receive an error like "unauthorize_access", remember that RedirectUri is required in IdentityServer configuration and clients.

GitHub now gives free users unlimited private repositories

github-unlimited-private-repositories

GitHub is by far the most popular way to build and share software. That said, one weakness of the platform is that it limits who can create private repositories – that is, software projects that aren’t visible to the broader public, and are shared only with a handful of pre-defined collaborators – to paying users.

Fortunately, that’s no longer the case, as GitHub today announced it was giving users of its free plan access to unlimited private repositories. This is great news for GitHub’s users, but there is a caveat, of course.

Private repositories on free accounts are limited to three collaborators apiece. So, while this might work for a small project (like, for example, a team competing in a hackathon), it isn’t particularly well-suited for actual commercial usage.

That was probably a deliberate move from GitHub. There’s little risk of the company cannibalizing its existing paid users with this new free offering.

Until recently, developers who wanted to create private git repositories without opening their wallets were forced to use a rival service – most frequently BitBucket. Today’s news, obviously, isn’t great for Atlassian’s flagship code sharing platform, but it does mean that coders aren’t forced to use two disparate code management services for their private and public projects

I also wonder what ubiquitous private repositories will mean for Github’s culture of self-exhibition and sharing.

Adding Swagger to Web API project

swagger_help_pages

Adding Swagger to your Web API does not replace ASP.NET Web API help pages (here the nuget package for Microsoft ASP.NET Web Api Help Page). You can have both running side by side, if desired.

To add Swagger to an ASP.NET Web Api, we will install an open source project called Swashbuckle via nuget.

Install-Package Swashbuckle –Version 5.2.1

After the package is installed, navigate to App_Start in the Solution Explorer. You’ll notice a new file called SwaggerConfig.cs. This file is where Swagger is enabled and any configuration options should be set here.

swagger_config-1

Configuring Swagger

At minimum you’ll need this line to enable Swagger and Swagger UI.

GlobalConfiguration.Configuration
  .EnableSwagger(c => c.SingleApiVersion("v1", "A title for your API"))
  .EnableSwaggerUi();

Start a new debugging session (F5) and navigate to http://localhost:[PORT_NUM]/swagger. You should see Swagger UI help pages for your APIs.

swagger_ui

Expanding an api and clicking the “Try it out!” button will make a call to that specific API and return results.

swagger_get_superhero-1

And then you see the response:

swagger_get_response

Enable Swagger to use XML comments

The minimum configuration is nice to get started but let’s add some more customization. We can tell Swashbuckle to use XML comments to add more details to the Swagger metadata. These are the same XML comments that ASP.NET Help Pages uses.

First, enable XML documentation file creation during build. In Solution Explorer right-click on the Web API project and click Properties. Click the Build tab and navigate to Output. Make sure XML documentation file is checked. You can leave the default file path. In my case its bin\SwaggerDemoApi.XML

build_xml_docs

Next, we need to tell Swashbuckle to include our XML comments in the Swagger metadata. Add the following line to SwaggerConfig.cs. Make sure to change the file path to the path of your XML documentation file.

GlobalConfiguration.Configuration
  .EnableSwagger(c =>
    {
      c.SingleApiVersion("v1", "SwaggerDemoApi");
      c.IncludeXmlComments(string.Format(@"{0}\bin\SwaggerDemoApi.XML",           
                           System.AppDomain.CurrentDomain.BaseDirectory));
    })
  .EnableSwaggerUi();

Finally, if you haven’t already, add XML comments to your Models and API methods.

xml_comments

Run the project and navigate back to /swagger. You should see more details added to your API documentation. I’ve highlighted a few below with their corresponding XML comment.

swagger_xml_comments

Under Response Class, click Model. You should see any XML comments added to your models.

swagger_xml_comments_model

Describing Enums As Strings

My Superhero class contains an Enum property called Universe which represents which comic universe they belong to.

universe_enum

By default, Swagger displays these Enum values as their integer value. This is not very descriptive. Let’s change it to display the string representation.

GlobalConfiguration.Configuration
  .EnableSwagger(c =>
  {
    c.SingleApiVersion("v1", "SwaggerDemoApi");
    c.IncludeXmlComments(string.Format(@"{0}\bin\SwaggerDemoApi.XML", 
                         System.AppDomain.CurrentDomain.BaseDirectory));
    c.DescribeAllEnumsAsStrings();
  })
  .EnableSwaggerUi();

If I look at Swagger now, the Universe Enum values are displayed as strings.

swagger_xml_comments_enum

These are just a few of the many configuration options you can specify in Swashbuckle to create your Swagger metadata. I encourage you to review the other options on Swashbuckle’s GitHub.

Happy coding!

Importing a BACPAC to SQL Server

We previously looked at Create a backup for Azure SQL Server and in today’s post we are going to address how to look at that data by restoring or importing it to a local SQL Server.

To start, open SQL Server Management Studio (SSMS) and connect to a local instance of SQL Server. Right-click on the instance name and select Import Data-tier Application.

AzureImportSQL1

Simply click Next to go back the welcome screen of the import wizard.

image

Click browse and locate the BACPAC file on your local computer. Click Next.

AzureImportSQL2

Alternately, change the radio button to Import from Windows Azure and click Connect. You will be prompted to enter your storage account name and access key and then locate the BACPAC in your storage account. This will be downloaded as part of the import process to a temporary directory that can also be specified in the wizard.

On the database settings page of the wizard the database name, data file storage path and log file storage paths can be modified. The default locations for the data and log files will be pulled from the model database. Click Next.

AzureImportSQL3

Click Finish on the Summary page to being the import.

AzureImportSQL4

Each step and the status of the operation will be displayed. Assuming all green check marks click Close on the wizard. If there are any errors click the link in the Result column to see the details behind the failure. There should also be a new database in the SQL Server object explorer carrying the same name specified on the Database Settings page of the import wizard.

AzureImportSQL5

This satisfies the full set of requirements given by the customer:

  • Full backup of the data, archived monthly for 10 years – this can be stored in Azure blob storage and/or downloaded and stored locally
  • Ability to restore the archive at any time – a BACPAC can be imported to Azure SQL Database or to a local SQL Server
  • Maintain data access should the customer decide to no longer leverage Azure SQL Database – BACPAC files can be imported to a local SQL Server instance

Create a backup for Azure SQL Database

Azure SQL Database is a managed database platform as a service (Paas) offering available from Microsoft in the Azure cloud. One of the advantages to Azure SQL Database is all the file management, server maintenance and backups are taken care of automatically. Point in time recovery is built directly into the service. The amount of time a user can go back and perform a point in time restore depends on the service tier selected.

Creating the BACPAC

To start, open a web browser and access the Azure portal (https://portal.azure.com). After signing in navigate to the SQL Databases section and select the database you want to archive.

AzureSql1

On the overview page click the Export button near the top of the page.

AzureSql2

On the resulting page name the BACPAC. Select the subscription and storage location where the BACPAC file will be saved. Enter the credentials that will be used to access the Azure SQL Server. Click OK at the bottom of the pane and the export process will begin in the background.

AzureSql3

If you don’t already have a storage, you can configure one. Go to All resources, Add a new resource and search for Storage account - blob, file, table, queue. Be careful: the name of the storage is lower case.

AzureSql4

Then in your new storage you have to create a container. You can create a container also in the Export process.

Under Activity log you can see the status of the export.

AzureSql5

When the process is finished, in your storage you have to file under Blobs, ready to download it.

This file is a zip file and contains the structure and data of your database. Now you can delete the storage on Azure (it costs money).

iPhone owners have less than two weeks to replace battery for £25

Why-Does-My-iPhone-Battery-Die-So-Fast-Heres-The-Real-Fix-828x466

Owners of iPhones with failing batteries have 12 days to take advantage of Apple’s out-of-warranty £25 battery swap offer before the price rises to as much as £65.

The discounted battery replacement scheme, which applies to the iPhone 6 and newer models, was launched following revelations last year that Apple was intentionally slowing iPhones because of worn batteries.

Apple apologised and reduced the cost of its out-of-warranty battery replacements for iPhone 6 and 6 Plus, 6S and 6S Plus, SE, 7 and 7 Plus, 8 and 8 Plus and iPhone X.

It also rolled out an iOS software update that showed the health of the phone’s battery and allowed users to switch off the feature that slowed their performance to avoid power problems.

If the iPhone reports that the battery is worn out or a user experiences slower performance because of an old battery, they can get it replaced in-store for £25 or via post for an additional £7.44 shipping fee.

But from 1 January, the cost of a battery replacement will increase to £45 for phones from the iPhone 6 or newer, or £65 for the iPhone X. The cost for older iPhones such as the 5S will be £79.

Battery replacements within the warranty period, or if the user has Apple’s extended warranty, AppleCare+, are free.

Microsoft officially announces 'Windows Sandbox' for running applications in isolation

Windows-Sandbox-Screenshot-open

Microsoft officially took the wraps off a feature expected to come to Windows 10 19H1 early next year that it has rechristened as "Windows Sandbox." This feature, which will be part of Windows 10 Pro and Enterprise editions, creates "an isolated, temporary desktop environment" where users can run potentially suspicious software, officials said in a blog post on December 18.

Earlier this year, Microsoft was rumored to be readying a new security feature for Windows 10 that was called, at that time, "InPrivate Desktop." InPrivate Desktop got a mention in Microsoft's Insider Feedback Hub during a bug-bash q1uest in August. The codename for InPrivate Desktop was "Madrid."

Quick start

  1. Install Windows 10 Pro or Enterprise, Insider build 18305 or newer
  2. Enable virtualization:
    • If you are using a physical machine, ensure virtualization capabilities are enabled in the BIOS.
    • If you are using a virtual machine, enable nested virtualization with this PowerShell cmdlet:
    • Set-VMProcessor -VMName <VMName> -ExposeVirtualizationExtensions $true
  3. Open Windows Features, and then select Windows Sandbox. Select OK to install Windows Sandbox. You might be asked to restart the computer. Optional-Windows-Features-dlg
  4. Using the Start menu, find Windows Sandbox, run it and allow the elevation
  5. Copy an executable file from the host
  6. Paste the executable file in the window of Windows Sandbox (on the Windows desktop)
  7. Run the executable in the Windows Sandbox; if it is an installer go ahead and install it
  8. Run the application and use it as you normally do
  9. When you’re done experimenting, you can simply close the Windows Sandbox application. All sandbox content will be discarded and permanently deleted
  10. Confirm that the host does not have any of the modifications that you made in Windows Sandbox.

Enable Developer Options on Samsung Galaxy S9

The Developer Options has many useful features that certainly elevate the usability, and user experience of an Android phone. In this tutorial, we are going to learn how to activate/enable Developer Options on Samsung Galaxy S9, and how to use it effectively. All Samsung smartphones come with an option, but it usually it comes hidden within the operating system. But it doesn’t mean that you can’t access it. And importantly, that is not a tough task either. The method is almost same as we perform on other Samsung’s smartphones.

  1. Open the app menu, and then tap on Settings.
  2. Scroll to locate ‘Device information‘ and tap on it.
  3. Next, locate the ‘Software info‘ and tap on it.
  4. Under the hood of this menu, find the ‘Build number‘.
  5. Now tap 7 times on ‘Build number’. Each time you tap on ‘Build number’, it displays a screen with a message about remaining taps to become a developer.
  6. This will activate the Developer Options on your phone:galaxy-s9-developer-options

Now, the Developer Options will appear under Settings.

How to Automatically Backup Your Web Server Files With WinSCP over FTP

WinSCPYou’ve heard it time and time again: back up your data. There are plenty of backup solutions, but nothing is better than an easy and free solution. So with a few lines of code and a very helpful program called WinSCP, we’re going to set up an automatic sync between your FTP server and your home computer.

Requirements

  • An FTP server and access credentials
  • A Windows computer
  • A copy of WinSCP (Windows only)

Setting Up WinSCP

Once you've downloaded your copy of WinSCP, install it on your computer. It also wouldn't be a bad idea to start remembering your FTP address, username, and password while WinSCP is installing.

From the login screen, enter your host name (i.e. ftp.puresourcecode.com), username, and password. You can use either FTP or SFTP, but be sure to change the port number the appropriate port your FTP host has provided you. Then click Save to save the profile. Open the profile to log into your FTP server. This will verify that you typed the right credentials in the profile.

image

Create the script

We’re going to create a simple script that logs into your FTP server, tells WinSCP where to download the missing files to on your computer, and then creates a log file that records FTP activity. Go ahead and open Notepad on your computer. Copy the following script template into Notepad:

option batch on
option confirm off
open ftp.puresourcecode.com
cd backups
option transfer binary
get /testremote* f:\backups\testlocal*
synchronize local f:\backups\testlocal testremote
exit

WinSCP will answer all prompts negatively to avoid holding up the script. Then it will automatically overwrite files when prompted. It then logs into your FTP server using the profile we created earlier, changes directories (if needed), and transfers binary (as opposed to ASCII). Finally, it reads the remote FTP directory and transfers files to the specified local directory. For even more options, check out the official WinSCP scripting page.

Now before you modify or run this script, we suggest creating test directories on both the remote and local targets. The last thing you want is to accidentally wipe your FTP server without any backups. So create a directory on your computer called “testlocal” (we created it under f:\backups) and another called “testremote” on your FTP server (we created it at the root). Once you run the script and it executes successfully, save it as “sync.txt” to your computer (we saved ours in our testlocal folder).

Automating the script

Now you’re ready to automate the script. For this we can use Task Scheduler.

image

Click on Create Basic Task and follow the following screens. First insert a name for your task.

image

Select when you want to start the task.

image

Select Start a program in the next screen.

image

Now click on Browse... and find WinSCP executable file in your program folder.

image

Underneath, add

/console /script=f:\backup\sync.txt /log=f:\backup\log.txt 

to Add arguments. Be sure to change the arguments if your sync.txt is in a different location and if you want to generate the log file in a different location. Click Next.

So the task is created!

Microsoft’s new Office icons are part of a bigger design overhaul

office_icons_HD_00007

Microsoft is modernizing its Office icons as part of a broader focus on design for its various Office apps. It’s the first time the Office icons have changed in five years, and they’re designed to be more simple and modern to span across multiple devices and platforms. Office now exists on Windows, Mac, iOS, and Android, and Microsoft has been building a single core codebase to make rapid monthly improvements to the apps. These icons are designed to reflect how Office has changed recently, with new AI features, more collaborative features, and its platform independence for key apps like Word, Excel, PowerPoint, and Outlook.

The new icons deemphasize the letter for each Office app, but still manage to look familiar. “Our design solution was to de-couple the letter and the symbol from the icons, essentially creating two panels (one for the letter and one for the symbol) that we can pair or separate,” explains Jon Friedman, partner director of design at Microsoft. “This allows us to maintain familiarity while still emphasizing simplicity when inside the app.”

Advertsing

125X125_06

Planet Xamarin

Planet Xamarin




TagCloud

MonthList