ASP.NET Accounts Management
들어가며
업무용 웹 애플리케이션 개발에서 사용자관리(Accounts Management)는 중요한 개발요소중 하나 입니다. ASP.NET에서 사용자관리에 대한 강좌를 하나 번역하면서 공부해 보도록 하겠습니다.
Web API Authentication & Authorization
CORS
Web API를 통해 Restful 서비스를 구현하면서 또 신경써야 할 부분중 하나 가 CORS(Cross-origin resource sharing)인것 같다. api서버와 application서버가 동일한 도메인에서 서비스 되면 별 문제 없겠지만, 다른 도메인에 있는 api를 호출할 경우 CORS를 고민해야 한다.(어떻게 표현해야 좋을지)
asp.net 사이트 참조 ##### AuthorizeAttribute를 이용하는 방법
AuthorizeAttribute를 override해서 cors origin이 특정 도메인인 경우 GenericPrincipal()로 가상의 인증정보를 만드는 방법이 있다. 잘 동작 하는것 같지만 사실은 cors와 인증을 구분하지 못하는 문제가 발생 하게 된다. 좋은 방법이 아니다.
using System; using System.Collections.Generic; using System.Linq; using System.Security.Principal; using System.Web; using System.Web.Http; using System.Web.Http.Controllers; namespace Basecamp.Api { ////// 임시권한처리를 위한 attribute /// api를 요청한 사이트의 호스트명을 조사해서 접근권한을 부여한다. /// public class TempAuthorizationFilterAttribute : AuthorizeAttribute { ////// callback /// /// </param> ///protected override bool IsAuthorized(HttpActionContext actionContext) { Uri url = HttpContext.Current.Request.Url; // api를 호출한 original address를 가져온다. Uri origin = HttpContext.Current.Request.UrlReferrer; //15/11/13 현재 인증체크를 위해 컨트롤러 위에다가 Authorize attribute를 추가하더라도 GenericPrincipal을 //만들어서 RequestContext에 포함하기 때문에 로그인 한것 같은 효과를 보게 된다. //이런 방법으로 처리하면 안되겠다.. if ( origin != null && (origin.Host == "basecamp.wrw.kr" || origin.Host == "dev.basecamp.wrw.kr" || origin.Host == "www.realgrid.com" || // 맵북 로컬 개발용 도메인 //origin.Host == "examples.onlydel.dev" || origin.Host == "dev.www.realgrid.com" || origin.Host == "www.realgrid.net" || (origin.Host == "localhost" && origin.Port == 49238) || (origin.Host == "winlocal" && origin.Port == 49238) || (origin.Host == "localhost" && origin.Port == 63111) ) ) { //role은 아직 관계 없으니 빼도되지만 일단 추가한다. actionContext.RequestContext.Principal = new GenericPrincipal(new GenericIdentity("tempUser"), new string[] { "admin" }); } //본인 호출 경로 if (url != null && (url.Host == "localhost" && url.Port == 55256)) { //role은 아직 관계 없으니 빼도되지만 일단 추가한다. actionContext.RequestContext.Principal = new GenericPrincipal(new GenericIdentity("debugUser"), new string[] { "admin" }); } return base.IsAuthorized(actionContext); } } }
EnableCors attribute
그래도 안되는데…
인터넷에는 이런 코드를 추가하라는 내용의 답변이 있는데 이것도….
<?xml version="1.0" encoding="utf-8"?> <configuration> <system.webServer> <httpProtocol> <customHeaders> <add name="Access-Control-Allow-Origin" value="*" /> <add name="Access-Control-Allow-Methods" value="GET, POST, PUT, DELETE, OPTIONS" /> </customHeaders> </httpProtocol> </system.webServer> </configuration> error XMLHttpRequest cannot load http://winlocal:49238/Token. The 'Access-Control-Allow-Origin' header contains multiple values 'http://examples.onlydel.dev, *', but only one is allowed. Origin 'http://examples.onlydel.dev' is therefore not allowed access.
오히려 이걸 하면 /token에도 접근이 안된다.
- Configure ASP.NET Identity with ASP.NET Web API (Accounts Management) – Part 1
- ASP.NET Identity 2.1 Accounts Confirmation, and Password/User Policy Configuration – Part 2
- Implement OAuth JSON Web Tokens Authentication in ASP.NET Web API and Identity 2.1 – Part 3
- ASP.NET Identity Role Based Authorization with ASP.NET Web API – Part 4
- ASP.NET Identity Authorization Access using Claims with ASP.NET Web API – Part 5
- AngularJS Authentication and Authorization with ASP.NET Web API and Identity – Part 6
참조
ASP.NET
- OS X(10.11)에 ASP.NET Application
- OS X(10.10)에 ASP.NET 5 설치하기
- MVC Web Application에서 재사용 가능한 Authentication라이브러리 만들기
- 맥에서 ASP.NET vNext 애플리케이션 개발하기
- ASP.NET 5소개
- ASP.NET 5와 MVC 6에서 바뀌게 되는 기능 Top 10
- ASP.NET 5 스케폴딩(Scaffolding)
- MVC Controller와 ApiController의 차이점
- ASP.NET Accounts Management
- MVC를 이용해 RealGrid에 데이터를 표현하기
EF
Visual Studio
- Visual Studio Code v0.3.0
- 무서운 EF
- 해결 방법을 찾을 수 없습니다.
- GitHub Extension for Visual Studio
- Visual Studio Code for Mac
- 패러렐즈 Visual Studio Text Editor 스크롤을 부드럽게 하는 방법
Another Code
- BitBucket!! 너는 또 뭐야?
- Git! 너 뭐야?
- 슬랙앱 만들기
- 품질의 기본
- 대화의 수준
- javascript tutorial
- html tutorial
- OS X에서 Paralles Windows 10 VM의 localhost 사이트에 접속하는 방법
- OS X(10.11)에서 MongoDB
- OS X(10.11)에서 SVN(Subversion)
- OS X(10.11)에서 아파치웹서버 구동하기 (Virtual Hosting 구현)
- OS X(10.11)에서 메이븐(Maven)사용하기
- Jasmine을 이용한 Javascript 테스트
- Identicon
- 회사의 슬픔
- 지킬에서 사이드 메뉴 필터링 하기
- ASP.NET MVC vs WEB API
- 티스토리에서 구문 하이라이팅 기능 구현하기
Javascript
- react를 위한 webpack정리 (II) - 작성중
- react를 위한 webpack정리 (I)
- javascript에서 객체 정의
- Javascripting
- aws-ec2-amazon linux-nodejs
- Protractor
- AngulaJS 연습
티스토리(1) tistory(1) syntax highlighting(1) Visual Studio(3) ASP.NET(4) EF(3) RealGrid(2) Jekyll(2) GitHub(3) SqlServer(1) SqlServer 2014(1) MVC(2) ASP.NET 5(7) Identity(2) Account(1) Controller(1) ApiController(1) 스케폴딩(2) Schaffolding(2) MVC 6(1) 페러렐즈(2) Parallels(1) Liquid(1) Authentication(1) Entity Framework(2) Visual Studio Code(2) VS(2) VisualStudio(2) Visual Studio 2015(2) VS 2015(2) Extension(1) 잡설(3) Update-Database(1) Entension(1) 일을하지말아야지(1) osx(2) DNX(2) Iendticon(1) Jasmine(1) AngularJS(2) protractor(1) maven(1) java(1) OSX(5) yosemite(2) 메이븐(1) 요세미티(1) 서브라임(1) 아파치(2) apache(1) webserver(1) 웹서버(1) virtualhost(1) svn(1) subversion(1) 몽고디비(1) mongodb(2) localhost(1) 호스팅(1) hosting(1) VSCode(1) html(1) JavaScript(1) nodejs(2) aws(2) ec2(2) git(4) javascript(5) object(1) webpack(2) reactjs(2) react(2) browserify(2) 웹팩(3) 리액트(3) slack(1) api(1) slack app(1) 슬랙 앱(1) 깃(2) 깃허브(1) github(1) 비트버킷(1) BitBucket(1)