Giter Site home page Giter Site logo

tfs-2017_cd_ci's Introduction

Continuous Integration & Continuous Delivery with Visual Studio TeamS ervices 2017, Visual Studio & Azure.

  • Setup Visual Studio Team Services 2017.

    • General.
      • Create Account
      • Create Project.
    • With TFSC.
    • With local Git repository.
    • With external Git repository.
  • Setup Visual studio 2017.

    • Add extensions.
    • Project Add to source control
  • Setup Azure as Publish environment.

Setup VSTS 2017.

https://www.visualstudio.com/team-services/

Sign in with your Microsoft account.

General.

  Create an Account.

  Create a Project.

Before we create a Build, we need a project. We use Visual Studio IDE.

Setup Visual studio 2017.

  • Setup VS 2017(add extension).
  • Share your existing code with Visual Studio 2017 and Team Services Git.
  • Add VS2017 solution "Add to source control" to GIT project in VSTS 2017(select project in Advanced).

Add extensions.

Tools > Extensions and Updates > (search for "Continuous Delivery Tools for Visual Studio")

##---------------------------------------------------------------------------------------------##

Setup Azure.

With local Git repository.

With external repository.

TFS-2017_CD_CI

TFS straat

Create the Azure app service.

  • Create App Service Plan
  • Create Web App
  • Link App Service Plan to VSTS.
  • Finish...............GoTo Setup Visual Studio Team Services 2017(VSTS)
  • Create development stack

Create Web App.

Link Team Service account to Azure subscription.

Create development stack from Azure portal.

Setup Visual Studio Team Services 2017(VSTS)

  • Create VSTS account selecting Git to manage code.
  • Create VSTS 2017 project selecting Git.
    • initialize with a README or gitignore.
    • build code from an external repository.

Initialize with a README or gitignore.

  • Set up Build

Build code from an external repository.

  • Set up Build

Set up Build.

  • Visual Studio
  • ASP.NET
  • ASP.NET Core

Setup Visual Studio 2017.

Setup TFS

Setup Azure

Setup Visual Studio

Share your code with Visual Studio 2017 and Team Services Git

  • Create repo from new project.
  • Create repo from existing code on your computer.
  • Clone an existing repo.

Create local Git repo.

Create a local Git repo for your project from an empty folder starting a new project.

Create new Git repo.

Setup TFS

Based on this repository.

###Project Directory

  • In Data/Migrations Add Folders
  • Configuration
  • Identity
  • PersistedGrants

Move the files of ApplicationDbContext Migration to Identity.

ApplicationDbContextModelSnapshot.cs
00000000000000_CreateIdentitySchema.cs

###Nuget Package Manager

Update Packages

Add to project:

IdentityServer4
IdentityServer4.AspNetIdentity
IdentityServer4.EntityFramework

###Connectionstring to DB

Open appsettings.json

Change DefaultConnection in ConnectionStrings in the file appsettings.json

{
"ConnectionStrings": {
  "DefaultConnection": "Server=<Server name>;Database=<Database name>;Trusted_Connection=True;MultipleActiveResultSets=true"
},
"Logging": {
  "IncludeScopes": false,
  "LogLevel": {
    "Default": "Warning"
  }
}
}

###Configure IdentityServer and the stores

####Startup

As before, IdentityServer needs to be configured in both ConfigureServices and in Configure in Startup.cs.

#####ConfigureServices

Modify your ConfigureServices in the Startup.cs to look like this:

        public void ConfigureServices(IServiceCollection services)
        {
            // Add framework services.
            services.AddDbContext<ApplicationDbContext>(options =>
                options.UseSqlServer(Configuration.GetConnectionString("DefaultConnection")));

            var migrationsAssembly = typeof(Startup).GetTypeInfo().Assembly.GetName().Name;

            services.AddIdentity<ApplicationUser, IdentityRole>()
                .AddEntityFrameworkStores<ApplicationDbContext>()
                .AddDefaultTokenProviders();

            services.AddMvc();

            // Add application services.
            services.AddTransient<IEmailSender, AuthMessageSender>();
            services.AddTransient<ISmsSender, AuthMessageSender>();
            services.AddTransient<IProfileService, IdentityWithAdditionalClaimsProfileService>();

            // add for identityserver
            services.AddIdentityServer()
                .AddTemporarySigningCredential()
                .AddOperationalStore(
                    builder => builder.UseSqlServer(Configuration.GetConnectionString("DefaultConnection"), options =>                  options.MigrationsAssembly(migrationsAssembly)))
                .AddConfigurationStore(
                    builder => builder.UseSqlServer(Configuration.GetConnectionString("DefaultConnection"), options => options.MigrationsAssembly(migrationsAssembly)))
                .AddAspNetIdentity<ApplicationUser>()
                .AddProfileService<IdentityWithAdditionalClaimsProfileService>();
        }

#####Configure

This shows both the template code generated for ASP.NET Identity, plus the additions needed for IdentityServer (just after UseIdentity). It’s important when using ASP.NET Identity that IdentityServer be registered after ASP.NET Identity in the pipeline because IdentityServer is relying upon the authentication cookie that ASP.NET Identity creates and manages.

Modify your Configure in the Startup.cs to look like this:

public void Configure(IApplicationBuilder app, IHostingEnvironment env, ILoggerFactory loggerFactory)
        {
            loggerFactory.AddConsole(Configuration.GetSection("Logging"));
            loggerFactory.AddDebug();

            if (env.IsDevelopment())
            {
                app.UseDeveloperExceptionPage();
                app.UseDatabaseErrorPage();

                // Browser Link is not compatible with Kestrel 1.1.0
                // For details on enabling Browser Link, see https://go.microsoft.com/fwlink/?linkid=840936
                // app.UseBrowserLink();
            }
            else
            {
                app.UseExceptionHandler("/Home/Error");
            }
           
            app.UseIdentity();
            
            app.UseIdentityServer();

            app.UseStaticFiles();
            
            app.UseMvc(routes =>
            {
                routes.MapRoute(
                    name: "default",
                    template: "{controller=Home}/{action=Index}/{id?}");
            });
        }

#####Adding migrations

PM> Add-Migration SetMigrationName -c ApplicationDbContext -o Data/Migrations/Identity

PM> Add-Migration SetMigrationName -c PersistedGrantDbContext -o Data/Migrations/PersistedGrants

PM> Add-Migration SetMigrationName -c ConfigurationDbContext -o Data/Migrations/Configuration

PM> Update-Database -c ApplicationDbContext

PM> Update-Database -c PersistedGrantDbContext

PM> Update-Database -c ConfigurationDbContext
 Add-Migration What is what?

 `-c ApplicationDbContext`
 Is the DbContext we are targeting

 `-o <ProjectName>\Data\Migrations\<DestinationFolder>`
 Is the file destination

 `SetMigrationName`
 Is the name we give of the Migration

 Update-Database What is what?

 `-c ApplicationDbContext`
 Is the DbContext we are targeting

Creating an MVC client

Add an MVC application to your solution. Use the ASP.NET Core “Web Application” template for that. No authentication.

Client Nuget Package Manager

Update Packages

Add to project:

Microsoft.AspNetCore.Authentication.Cookies
Microsoft.AspNetCore.Authentication.OpenIdConnect

Next add both middlewares to your pipeline - the cookies one is simple:

app.UseCookieAuthentication(new CookieAuthenticationOptions
{
    AuthenticationScheme = "Cookies"
});

The OpenID Connect middleware needs slightly more configuration. You point it to your IdentityServer, specify a client ID and tell it which middleware will do the local signin (namely the cookies middleware). As well, we’ve turned off the JWT claim type mapping to allow well-known claims (e.g. ‘sub’ and ‘idp’) to flow through unmolested. This “clearing” of the claim type mappings must be done before the call to UseOpenIdConnectAuthentication():

JwtSecurityTokenHandler.DefaultInboundClaimTypeMap.Clear();

app.UseOpenIdConnectAuthentication(new OpenIdConnectOptions
{
    AuthenticationScheme = "oidc",
    SignInScheme = "Cookies",

    Authority = "http://localhost:5000",
    RequireHttpsMetadata = false,

    ClientId = "mvc",
    SaveTokens = true
});

Both middlewares should be added before the MVC in the pipeline.

The last step is to trigger the authentication handshake. For that go to the home controller and add the [Authorize] on one of the actions. Also modify the view of that action to display the claims of the user, e.g.:

<dl>
    @foreach (var claim in User.Claims)
    {
        <dt>@claim.Type</dt>
        <dd>@claim.Value</dd>
    }
</dl>

tfs-2017_cd_ci's People

Contributors

dev-petervanhemert avatar

Watchers

James Cloos avatar Peter avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.