/// <summary> /// Acquires the access token and related parameters that go into the formulation of the token endpoint's response to a /// client. /// </summary> /// <param name="accessTokenRequestMessage"> /// Details regarding the resources that the access token will grant access to, and the identity of the client /// that will receive that access. /// Based on this information the receiving resource server can be determined and the lifetime of the access /// token can be set based on the sensitivity of the resources. /// </param> /// <returns>A non-null parameters instance that DotNetOpenAuth will dispose after it has been used.</returns> public AccessTokenResult CreateAccessToken(IAccessTokenRequest accessTokenRequestMessage) { TimeSpan clientApplicationLifetime = GetClientLifetime(accessTokenRequestMessage); var accessToken = new AuthorizationServerAccessToken { // Note: all other fields are assigned by IsAuthorizationValid() (i.e. ClientIdentifier, Scope, User and UtcIssued) // Set the crypto keys for accessing the secured services (assume there is only one secured service) AccessTokenSigningKey = CryptoKeyProvider.GetCryptoKey(CryptoKeyType.AuthZServer).PrivateEncryptionKey, ResourceServerEncryptionKey = GetRequestedSecureResourceCryptoKey(), // Set the limited lifetime of the token Lifetime = (clientApplicationLifetime != TimeSpan.Zero) ? clientApplicationLifetime : TimeSpan.FromMinutes(DefaultLifetime), }; // Insert user specific information string username = GetUserFromAccessTokenRequest(accessTokenRequestMessage); if (username.HasValue()) { IUserAuthInfo user = GetUserAuthInfo(username); if (user != null) { accessToken.ExtraData.Add(new KeyValuePair <string, string>( RequireAuthorizationAttribute.ExtraDataRoles, String.Join(@",", user.Roles))); } } return(new AccessTokenResult(accessToken)); }
public static void Main(string[] args) { var cryptoKeyProvider = new CryptoKeyProvider(); var privateKey = cryptoKeyProvider.GenerateKey(); var publicKey = cryptoKeyProvider.ExtractPublicKey(privateKey); Console.WriteLine("Public Key:"); Console.WriteLine(publicKey.Contents); Console.WriteLine(); var licenseCriteria = new LicenseCriteria { ExpirationDate = DateTimeOffset.UtcNow.AddDays(30), IssueDate = DateTimeOffset.UtcNow, Id = Guid.NewGuid(), MetaData = new Dictionary <string, string> { { "LicensedCores", "2" } }, Type = "Subscription" }; var license = new LicenseGenerator().Generate(privateKey, licenseCriteria); Console.WriteLine(license.Document); Console.WriteLine(); Console.ReadKey(); }
public MainForm() { _cryptoKeyProvider = new CryptoKeyProvider(); _cryptoKeyProvider.AddOrChangeKey(0, new byte[] { 0x54, 0x90, 0xd8, 0xab, 0xbc, 0xd3, 0xf7, 0xe4, 0x58, 0x37, 0xb8, 0xb3, 0x45 }); _cryptoKeyProvider.AddOrChangeKey(1, new byte[] { 0x37, 0x56, 0x3e, 0x4b, 0xc6, 210, 0x79, 0x20, 0x9a, 0xdb, 0xc0, 0xfe, 0xcd, 0xf4 }); InitializeComponent(); timer1.Enabled = false; }
private RSACryptoServiceProvider GetRequestedSecureResourceCryptoKey() { return(CryptoKeyProvider.GetCryptoKey(CryptoKeyType.ApiService).PublicSigningKey); }