Skip to content

Commit

Permalink
update
Browse files Browse the repository at this point in the history
  • Loading branch information
ebubekirdgn committed Feb 15, 2023
1 parent 97f018b commit 40dd81a
Show file tree
Hide file tree
Showing 376 changed files with 78,640 additions and 1,090 deletions.
Binary file modified Microservices/.vs/Microservices/DesignTimeBuild/.dtbcache.v2
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
1,011 changes: 0 additions & 1,011 deletions Microservices/.vs/Microservices/config/applicationhost.config

This file was deleted.

Binary file modified Microservices/.vs/Microservices/v17/.futdcache.v2
Binary file not shown.
Binary file modified Microservices/.vs/Microservices/v17/.suo
Binary file not shown.
Binary file not shown.
Binary file modified Microservices/.vs/ProjectEvaluation/microservices.projects.v5.2
Binary file not shown.
63 changes: 63 additions & 0 deletions Microservices/IdentityServer/FreeCourse.IdentityServer/Config.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
// Copyright (c) Brock Allen & Dominick Baier. All rights reserved.
// Licensed under the Apache License, Version 2.0. See LICENSE in the project root for license information.

using IdentityServer4;
using IdentityServer4.Models;
using System;
using System.Collections.Generic;

namespace FreeCourse.IdentityServer
{
public static class Config
{
public static IEnumerable<ApiResource> ApiResources => new ApiResource[]
{
new ApiResource("resource_catalog"){Scopes= {"catalog_fullpermission"} },
new ApiResource("photo_stock_catalog"){Scopes= { "photo_stock_fullpermission" } },
new ApiResource(IdentityServerConstants.LocalApi.ScopeName)
};

public static IEnumerable<IdentityResource> IdentityResources =>
new IdentityResource[]
{
new IdentityResources.Email(), //email
new IdentityResources.OpenId(),//sub
new IdentityResources.Profile(),
new IdentityResource(){Name = "roles",DisplayName = "Role", Description="Kullanıcı Rolleri",UserClaims=new[]{ "role"} },
};

public static IEnumerable<ApiScope> ApiScopes =>
new ApiScope[]
{
new ApiScope("catalog_fullpermission","Catalog API icin full erisim"),
new ApiScope("photo_stock_fullpermission","Photo Stock API icin full erisim"),
new ApiScope(IdentityServerConstants.LocalApi.ScopeName)
};

public static IEnumerable<Client> Clients =>
new Client[]
{
new Client
{
ClientId = "WebMvcClient",
ClientName = "Asp.Net Core MVC",
ClientSecrets = { new Secret("secret".Sha256())},
AllowedGrantTypes = GrantTypes.ClientCredentials,
AllowedScopes= { "catalog_fullpermission", "photo_stock_fullpermission",IdentityServerConstants.LocalApi.ScopeName }
},
new Client
{
ClientId = "WebMvcClientForUser",
ClientName = "Asp.Net Core MVC",
AllowOfflineAccess = true,
ClientSecrets = { new Secret("secret".Sha256())},
AllowedGrantTypes = GrantTypes.ResourceOwnerPassword,
AllowedScopes= { IdentityServerConstants.StandardScopes.OpenId, IdentityServerConstants.StandardScopes.Email, IdentityServerConstants.StandardScopes.Profile, IdentityServerConstants.StandardScopes.OfflineAccess, IdentityServerConstants.LocalApi.ScopeName, "roles" },
AccessTokenLifetime = 1*60*60, // 1 saat
RefreshTokenExpiration = TokenExpiration.Absolute,
AbsoluteRefreshTokenLifetime= (int)(DateTime.Now.AddDays(60)-DateTime.Now).TotalSeconds, // 60 gün tutsun dedik.
RefreshTokenUsage = TokenUsage.ReUse
}
};
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
using FreeCourse.IdentityServer.Dtos;
using FreeCourse.IdentityServer.Models;
using FreeCourse.Shared.Dtos;
using Microsoft.AspNetCore.Authorization;
using Microsoft.AspNetCore.Identity;

using Microsoft.AspNetCore.Mvc;
using Microsoft.IdentityModel.JsonWebTokens;
using System.Linq;
using System.Threading.Tasks;
using static IdentityServer4.IdentityServerConstants;

namespace FreeCourse.IdentityServer.Controllers
{
[Authorize(LocalApi.PolicyName)]
[Route("api/[controller]/[action]")]
[ApiController]
public class UserController : ControllerBase
{
private readonly UserManager<ApplicationUser> _userManager;

public UserController(UserManager<ApplicationUser> userManager)
{
_userManager = userManager;
}

[HttpPost]
public async Task<IActionResult> SignUp(SignupDto signupDto)
{
var user = new ApplicationUser
{
UserName = signupDto.Username,
Email = signupDto.Email,
City = signupDto.City,
};
var result = await _userManager.CreateAsync(user, signupDto.Password);
if (!result.Succeeded)
{
return BadRequest(Response<NoContent>.Fail(result.Errors.Select(x => x.Description).ToList(), 400));
}
return NoContent();
}

[HttpGet]
public async Task<IActionResult> GetUser()
{
var userClaim = User.Claims.FirstOrDefault(x => x.Type == JwtRegisteredClaimNames.Sub);
if (userClaim is null)
{
return BadRequest();
}
var user = await _userManager.FindByIdAsync(userClaim.Value);
if (user is null)
{
return BadRequest();
}
return Ok(new { Id = user.Id, UserName = user.UserName, Email = user.Email, City=user.City});
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
using Microsoft.AspNetCore.Identity.EntityFrameworkCore;
using Microsoft.EntityFrameworkCore;
using FreeCourse.IdentityServer.Models;

namespace FreeCourse.IdentityServer.Data
{
public class ApplicationDbContext : IdentityDbContext<ApplicationUser>
{
public ApplicationDbContext(DbContextOptions<ApplicationDbContext> options)
: base(options)
{
}

protected override void OnModelCreating(ModelBuilder builder)
{
base.OnModelCreating(builder);
// Customize the ASP.NET Identity model and override the defaults if needed.
// For example, you can rename the ASP.NET Identity table names and more.
// Add your customizations after calling base.OnModelCreating(builder);
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
namespace FreeCourse.IdentityServer.Dtos
{
public class SignupDto
{
public string Email { get; set; }
public string Username { get; set; }
public string Password { get; set; }
public string City { get; set; }
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
<Project Sdk="Microsoft.NET.Sdk.Web">

<PropertyGroup>
<TargetFramework>netcoreapp3.1</TargetFramework>
</PropertyGroup>

<ItemGroup>
<PackageReference Include="IdentityServer4.AspNetIdentity" Version="4.0.0" />

<PackageReference Include="Microsoft.AspNetCore.Authentication.Google" Version="3.1.5" />

<PackageReference Include="Microsoft.EntityFrameworkCore.SqlServer" Version="3.1.5" />
<PackageReference Include="Serilog.AspNetCore" Version="3.2.0" />

<PackageReference Include="Microsoft.AspNetCore.Diagnostics.EntityFrameworkCore" Version="3.1.5" />
<PackageReference Include="Microsoft.EntityFrameworkCore.Sqlite" Version="3.1.5" />
<PackageReference Include="Microsoft.EntityFrameworkCore.Tools" Version="3.1.5">
<PrivateAssets>all</PrivateAssets>
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
</PackageReference>

<PackageReference Include="Microsoft.AspNetCore.Identity.EntityFrameworkCore" Version="3.1.5" />
<PackageReference Include="Microsoft.AspNetCore.Identity.UI" Version="3.1.5" />
</ItemGroup>

<ItemGroup>
<ProjectReference Include="..\..\Shared\FreeCourse.Shared\FreeCourse.Shared.csproj" />
</ItemGroup>

<ItemGroup>
<Compile Update="Properties\Resources.Designer.cs">
<DesignTime>True</DesignTime>
<AutoGen>True</AutoGen>
<DependentUpon>Resources.resx</DependentUpon>
</Compile>
</ItemGroup>

<ItemGroup>
<EmbeddedResource Update="Properties\Resources.resx">
<Generator>ResXFileCodeGenerator</Generator>
<LastGenOutput>Resources.Designer.cs</LastGenOutput>
</EmbeddedResource>
</ItemGroup>
</Project>
Loading

0 comments on commit 40dd81a

Please sign in to comment.