//-----------------------------------------------------------------------
//
// Copyright (c) Outercurve Foundation. All rights reserved.
//
//-----------------------------------------------------------------------
namespace DotNetOpenAuth.OAuth2 {
using System;
using System.Collections.Generic;
using System.Diagnostics.Contracts;
using System.Linq;
using System.Security.Cryptography;
using System.Text;
using DotNetOpenAuth.Messaging;
using DotNetOpenAuth.Messaging.Bindings;
using DotNetOpenAuth.OAuth2.ChannelElements;
using DotNetOpenAuth.OAuth2.Messages;
///
/// Provides host-specific authorization server services needed by this library.
///
[ContractClass(typeof(IAuthorizationServerContract))]
public interface IAuthorizationServer {
///
/// Gets the store for storeing crypto keys used to symmetrically encrypt and sign authorization codes and refresh tokens.
///
///
/// This store should be kept strictly confidential in the authorization server(s)
/// and NOT shared with the resource server. Anyone with these secrets can mint
/// tokens to essentially grant themselves access to anything they want.
///
ICryptoKeyStore CryptoKeyStore { get; }
///
/// Gets the authorization code nonce store to use to ensure that authorization codes can only be used once.
///
/// The authorization code nonce store.
INonceStore VerificationCodeNonceStore { get; }
///
/// Gets the crypto service provider with the asymmetric private key to use for signing access tokens.
///
/// A crypto service provider instance that contains the private key.
/// Must not be null, and must contain the private key.
///
/// The public key in the private/public key pair will be used by the resource
/// servers to validate that the access token is minted by a trusted authorization server.
///
RSACryptoServiceProvider AccessTokenSigningKey { get; }
///
/// Obtains the lifetime for a new access token.
///
///
/// 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.
///
///
/// Receives the lifetime for this access token. Note that within this lifetime, authorization may not be revokable.
/// Short lifetimes are recommended (i.e. one hour), particularly when the client is not authenticated or
/// the resources to which access is being granted are sensitive.
///
TimeSpan GetAccessTokenLifetime(IAccessTokenRequest accessTokenRequestMessage);
///
/// Obtains the encryption key for an access token being created.
///
///
/// 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.
///
///
/// The crypto service provider with the asymmetric public key to use for encrypting access tokens for a specific resource server.
/// The caller is responsible to dispose of this value.
///
///
/// The caller is responsible to dispose of the returned value.
///
RSACryptoServiceProvider GetResourceServerEncryptionKey(IAccessTokenRequest accessTokenRequestMessage);
///
/// Gets the client with a given identifier.
///
/// The client identifier.
/// The client registration. Never null.
/// Thrown when no client with the given identifier is registered with this authorization server.
IClientDescription GetClient(string clientIdentifier);
///
/// Determines whether a described authorization is (still) valid.
///
/// The authorization.
///
/// true if the original authorization is still valid; otherwise, false.
///
///
/// When establishing that an authorization is still valid,
/// it's very important to only match on recorded authorizations that
/// meet these criteria:
/// 1) The client identifier matches.
/// 2) The user account matches.
/// 3) The scope on the recorded authorization must include all scopes in the given authorization.
/// 4) The date the recorded authorization was issued must be no later that the date the given authorization was issued.
/// One possible scenario is where the user authorized a client, later revoked authorization,
/// and even later reinstated authorization. This subsequent recorded authorization
/// would not satisfy requirement #4 in the above list. This is important because the revocation
/// the user went through should invalidate all previously issued tokens as a matter of
/// security in the event the user was revoking access in order to sever authorization on a stolen
/// account or piece of hardware in which the tokens were stored.
///
bool IsAuthorizationValid(IAuthorizationDescription authorization);
}
///
/// Code Contract for the interface.
///
[ContractClassFor(typeof(IAuthorizationServer))]
internal abstract class IAuthorizationServerContract : IAuthorizationServer {
///
/// Prevents a default instance of the class from being created.
///
private IAuthorizationServerContract() {
}
///
/// Gets the store for storeing crypto keys used to symmetrically encrypt and sign authorization codes and refresh tokens.
///
ICryptoKeyStore IAuthorizationServer.CryptoKeyStore {
get {
Contract.Ensures(Contract.Result() != null);
throw new NotImplementedException();
}
}
///
/// Gets the authorization code nonce store to use to ensure that authorization codes can only be used once.
///
/// The authorization code nonce store.
INonceStore IAuthorizationServer.VerificationCodeNonceStore {
get {
Contract.Ensures(Contract.Result() != null);
throw new NotImplementedException();
}
}
///
/// Gets the crypto service provider with the asymmetric private key to use for signing access tokens.
///
///
/// Must not be null, and must contain the private key.
///
/// A crypto service provider instance that contains the private key.
RSACryptoServiceProvider IAuthorizationServer.AccessTokenSigningKey {
get {
Contract.Ensures(Contract.Result() != null);
Contract.Ensures(!Contract.Result().PublicOnly);
throw new NotImplementedException();
}
}
///
/// Obtains the lifetime for a new access token.
///
/// 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.
///
/// Receives the lifetime for this access token. Note that within this lifetime, authorization may not be revokable.
/// Short lifetimes are recommended (i.e. one hour), particularly when the client is not authenticated or
/// the resources to which access is being granted are sensitive.
///
TimeSpan IAuthorizationServer.GetAccessTokenLifetime(IAccessTokenRequest accessTokenRequestMessage) {
Requires.NotNull(accessTokenRequestMessage, "accessTokenRequestMessage");
throw new NotImplementedException();
}
///
/// Obtains the encryption key for an access token being created.
///
/// 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.
///
/// The crypto service provider with the asymmetric public key to use for encrypting access tokens for a specific resource server.
/// The caller is responsible to dispose of this value.
///
RSACryptoServiceProvider IAuthorizationServer.GetResourceServerEncryptionKey(IAccessTokenRequest accessTokenRequestMessage) {
Requires.NotNull(accessTokenRequestMessage, "accessTokenRequestMessage");
Contract.Ensures(Contract.Result() != null);
throw new NotImplementedException();
}
///
/// Gets the client with a given identifier.
///
/// The client identifier.
/// The client registration. Never null.
/// Thrown when no client with the given identifier is registered with this authorization server.
IClientDescription IAuthorizationServer.GetClient(string clientIdentifier) {
Requires.NotNullOrEmpty(clientIdentifier, "clientIdentifier");
Contract.Ensures(Contract.Result() != null);
throw new NotImplementedException();
}
///
/// Determines whether a described authorization is (still) valid.
///
/// The authorization.
///
/// true if the original authorization is still valid; otherwise, false.
///
///
/// When establishing that an authorization is still valid,
/// it's very important to only match on recorded authorizations that
/// meet these criteria:
/// 1) The client identifier matches.
/// 2) The user account matches.
/// 3) The scope on the recorded authorization must include all scopes in the given authorization.
/// 4) The date the recorded authorization was issued must be no later that the date the given authorization was issued.
/// One possible scenario is where the user authorized a client, later revoked authorization,
/// and even later reinstated authorization. This subsequent recorded authorization
/// would not satisfy requirement #4 in the above list. This is important because the revocation
/// the user went through should invalidate all previously issued tokens as a matter of
/// security in the event the user was revoking access in order to sever authorization on a stolen
/// account or piece of hardware in which the tokens were stored.
///
bool IAuthorizationServer.IsAuthorizationValid(IAuthorizationDescription authorization) {
Requires.NotNull(authorization, "authorization");
throw new NotImplementedException();
}
}
}