// POST api/issue public HttpResponseMessage Post(TokenRequest rst) { Uri scope = rst.Scope; if (scope == null) { return(Request.CreateResponse <TokenResponse>(HttpStatusCode.BadRequest, new TokenResponse() { Error = OAuthError.INVALID_REQUEST })); } string key = OAuthConfiguration.Configuration.StsSettings.SymmetricKey; TimeSpan lifeTime = new TimeSpan(0, 0, OAuthConfiguration.Configuration.StsSettings.TokenLifeTimeInSec); var claims = new List <Claim>(); claims.Add(new Claim(ClaimTypes.Name, this.User.Identity.Name)); claims.Add(new Claim(ClaimTypes.Role, "AssetsServiceUser")); claims.Add(new Claim(ClaimTypes.Role, "Developer")); claims.Add(new Claim(ClaimTypes.Role, "Administrator")); SimpleWebToken token = new SimpleWebToken(scope, OAuthConfiguration.Configuration.StsSettings.IssuerUri.ToString(), DateTime.UtcNow + lifeTime, claims, key); var tokenResponse = new TokenResponse() { AccessToken = token.ToString(), TokenType = "bearer", ExpiresIn = 600 }; return(Request.CreateResponse <TokenResponse>(HttpStatusCode.OK, tokenResponse)); }
public void ToStringReturnsCorrectResult(string[] keysAndValues, string expected) { var claims = keysAndValues.Select(k => k.Split('|')) .Select(k => new Claim(k[0], k[1])) .ToArray(); var sut = new SimpleWebToken(claims); var actual = sut.ToString(); Assert.Equal(expected, actual); }
public void ToStringReturnsCorrectResult(string[] keysAndValues, string expected) { var claims = keysAndValues .Select(s => s.Split('|')) .Select(s => new Claim(s[0], s[1])) .ToArray(); var sut = new SimpleWebToken(claims); var actual = sut.ToString(); Assert.Equal(expected, actual); }
public void ToStringShouldBeRight(string[] action, string expected) { //var expected = new[] // { // new Claim("foo", "bar") // }; var claims = action.Select(s => s.Split('|')).Select(a => new Claim(a[0], a[1])).ToArray(); var sut = new SimpleWebToken(claims); Assert.Equal(expected, sut.ToString()); }
public void ToStringReturnsCorrectResult( string[] keysAndValues, string expected) { // Fixture setup var claims = keysAndValues .Select(s => s.Split('|')) .Select(a => new Claim(a[0], a[1])) .ToArray(); var sut = new SimpleWebToken(claims); // Exercise system var actual = sut.ToString(); // Verify outcome Assert.Equal(expected, actual); }
private static string CreateSwtToken() { var signingKey = "wAVkldQiFypTQ+kdNdGWCYCHRcee8XmXxOvgmak8vSY="; var audience = "http://websample"; var issuer = "http://self"; var token = new SimpleWebToken(issuer, audience, Convert.FromBase64String(signingKey)); token.AddClaim(ClaimTypes.Name, "dominick"); token.AddClaim(ClaimTypes.Email, "*****@*****.**"); token.AddClaim(ClaimTypes.Role, "Users"); token.AddClaim(ClaimTypes.Role, "Administrators"); token.AddClaim("simple", "test"); return token.ToString(); }
private static string CreateSwtToken() { var signingKey = "wAVkldQiFypTQ+kdNdGWCYCHRcee8XmXxOvgmak8vSY="; var audience = "http://websample"; var issuer = "http://self"; var token = new SimpleWebToken(issuer, audience, Convert.FromBase64String(signingKey)); token.AddClaim(ClaimTypes.Name, "dominick"); token.AddClaim(ClaimTypes.Email, "*****@*****.**"); token.AddClaim(ClaimTypes.Role, "Users"); token.AddClaim(ClaimTypes.Role, "Administrators"); token.AddClaim("simple", "test"); return(token.ToString()); }
/// <summary> /// Requests an SWT Token using an input SWT token. /// </summary> /// <param name="token">The input SWT token.</param> /// <param name="scope">The requested scope.</param> /// <returns>The requested SWT token</returns> public SimpleWebToken Issue(SimpleWebToken token, Uri scope) { return(IssueAssertion(token.ToString(), "SWT", scope)); }