5

우리는 REST 기반 서비스에 대해 STS (클레임 기반 인증)를 구현하고 있습니다. JSON을 사용하여 REST 서비스를 작성하기로 결정한 이유 중 상당수는 철저히 작아졌습니다. STS에서는 SAML 크기가 몇 K 바이트가된다는 몇 가지 주장 만있는 SAML 토큰이 있습니다. 우리가 객체의 목록을 반환하지 않는 대부분의 REST 호출의 경우 응답 크기는 100 바이트가 낮으며 이러한 호출의 경우이 토큰은 너무 많은 오버 헤드로 보입니다. 프로젝트에서 어떻게 이것을 처리합니까?SAML 토큰 크기 및 REST

답변

0

REST 엔드 포인트와 함께 SAML 토큰을 사용할 수 있지만 대신 SWT (Simple Web Tokens)를 사용하는 사람들을 찾을 수 있습니다. 더 작고 간단합니다.

ACS (Windows Azure Platform의 액세스 제어 서비스)는이를 구현합니다.

+0

SWT가 앞으로 나아가지는 않는 것처럼 보입니다. JWT도 초기 단계에 있습니다. 지금 SAML을 다루어야하는 것 같습니다. http://startersts.codeplex.com/discussions/242113?ProjectName=startersts –

2

... 또는 JWT (JSon Web Token). ACS도이를 지원합니다. 문서 확인 : JSON Web Token Handler for the Microsoft .NET Framework 4.5 대칭 키 기반 HMAC SHA256으로 서명 된 JWT를 발행하고 유효성을 검사하는 .Net 4.5가있는이 라이브러리의 사용 예는 다음과 같습니다.

string jwtIssuer = "MyIssuer"; 
string jwtAudience = "MyAudience"; 

// Generate symmetric key for HMAC-SHA256 signature 
RNGCryptoServiceProvider cryptoProvider = new RNGCryptoServiceProvider(); 
byte[] keyForHmacSha256 = new byte[64]; 
cryptoProvider.GetNonZeroBytes(keyForHmacSha256); 

/////////////////////////////////////////////////////////////////// 
// Create signing credentials for the signed JWT. 
// This object is used to cryptographically sign the JWT by the issuer. 
SigningCredentials sc = new SigningCredentials(
           new InMemorySymmetricSecurityKey(keyForHmacSha256), 
           "http://www.w3.org/2001/04/xmldsig-more#hmac-sha256", 
           "http://www.w3.org/2001/04/xmlenc#sha256"); 

/////////////////////////////////////////////////////////////////// 
// Create token validation parameters for the signed JWT 
// This object will be used to verify the cryptographic signature of the received JWT 
TokenValidationParameters validationParams = 
    new TokenValidationParameters() 
    { 
     AllowedAudience = s_jwtAudience, 
     ValidIssuer = s_jwtIssuer, 
     ValidateExpiration = true, 
     ValidateNotBefore = true, 
     ValidateIssuer = true, 
     ValidateSignature = true, 
     SigningToken = new BinarySecretSecurityToken(keyForHmacSha256), 
    }; 

/////////////////////////////////////////////////////////////////// 
// Create JWT handler 
// This object is used to write/sign/decode/validate JWTs 
JWTSecurityTokenHandler jwtHandler = new JWTSecurityTokenHandler(); 

// Create a simple JWT claim set 
IList<Claim> payloadClaims = new List<Claim>() { new Claim("clm1", "clm1 value"), }; 

// Create a JWT with signing credentials and lifetime of 12 hours 
JWTSecurityToken jwt = 
    new JWTSecurityToken(jwtIssuer, jwtAudience, payloadClaims, sc, DateTime.UtcNow, DateTime.UtcNow.AddHours(12.0)); 

// Serialize the JWT 
// This is how our JWT looks on the wire: <Base64UrlEncoded header>.<Base64UrlEncoded body>.<signature> 
string jwtOnTheWire = jwtHandler.WriteToken(jwt); 

// Validate the token signature (we provide the shared symmetric key in `validationParams`) 
// This will throw if the signature does not validate 
jwtHandler.ValidateToken(jwtOnTheWire, validationParams); 

// Parse JWT from the Base64UrlEncoded wire form (<Base64UrlEncoded header>.<Base64UrlEncoded body>.<signature>) 
JWTSecurityToken parsedJwt = jwtHandler.ReadToken(jwtOnTheWire) as JWTSecurityToken; 
+0

대칭 키를 사용할 수있는 기능이없는 것 같습니다. 막히는 종류 :-( –

+1

나는 당신이 무엇을 의미하는지 알지 못하지만, 위의 대답을 업데이트하여 JWT를 생성, 서명, 직렬화 한 다음 역 과정을 수행하는 코드 조각을 보여주었습니다. – Kastorskij

+0

예 ! 내가 필요로하는 것만 큼 완벽 해. 고마워 !!! –