Example #1
0
        /// <summary>
        /// Initializes a new instance of the <see cref="OAuthPrincipal"/> class.
        /// </summary>
        /// <param name="token">The access token.</param>
        internal OAuthPrincipal(IServiceProviderAccessToken token)
            : this(token.Username, token.Roles)
        {
            Contract.Requires(token != null);

            this.AccessToken = token.Token;
        }
Example #2
0
        /// <summary>
        /// Initializes a new instance of the <see cref="OAuthPrincipal"/> class.
        /// </summary>
        /// <param name="token">The access token.</param>
        internal OAuthPrincipal(IServiceProviderAccessToken token)
            : this(token.Username, token.Roles)
        {
            Contract.Requires <ArgumentNullException>(token != null);

            this.AccessToken = token.Token;
        }
        /// <summary>
        /// Initializes a new instance of the <see cref="OAuth1Principal"/> class.
        /// </summary>
        /// <param name="token">The access token.</param>
        internal OAuth1Principal(IServiceProviderAccessToken token)
            : base(token.Username, token.Roles)
        {
            Requires.NotNull(token, "token");

            this.AccessToken = token.Token;
        }
Example #4
0
        /// <summary>
        /// Creates a security principal that may be used.
        /// </summary>
        /// <param name="request">The request.</param>
        /// <returns>The <see cref="IPrincipal"/> instance that can be used for access control of resources.</returns>
        public OAuthPrincipal CreatePrincipal(AccessProtectedResourceRequest request)
        {
            Requires.NotNull(request, "request");

            IServiceProviderAccessToken accessToken = this.TokenManager.GetAccessToken(request.AccessToken);

            return(new OAuth1Principal(accessToken));
        }
Example #5
0
        /// <summary>
        /// Creates a security principal that may be used.
        /// </summary>
        /// <param name="request">The request.</param>
        /// <returns>The <see cref="IPrincipal"/> instance that can be used for access control of resources.</returns>
        public IPrincipal CreatePrincipal(AccessProtectedResourceRequest request)
        {
            Requires.NotNull(request, "request");

            IServiceProviderAccessToken accessToken = this.TokenManager.GetAccessToken(request.AccessToken);

            return(OAuthPrincipal.CreatePrincipal(accessToken.Username, accessToken.Roles));
        }
Example #6
0
        /// <summary>
        /// Creates a security principal that may be used.
        /// </summary>
        /// <param name="request">The request.</param>
        /// <returns>The <see cref="IPrincipal"/> instance that can be used for access control of resources.</returns>
        public OAuthPrincipal CreatePrincipal(AccessProtectedResourceRequest request)
        {
            Contract.Requires <ArgumentNullException>(request != null);

            IServiceProviderAccessToken accessToken = this.TokenManager.GetAccessToken(request.AccessToken);

            return(new OAuthPrincipal(accessToken));
        }
        /// <summary>
        /// Ensures that access tokens have not yet expired.
        /// </summary>
        /// <param name="message">The incoming message carrying the access token.</param>
        private void VerifyThrowTokenNotExpired(AccessProtectedResourceRequest message)
        {
            Requires.NotNull(message, "message");

            try {
                IServiceProviderAccessToken token = this.tokenManager.GetAccessToken(message.AccessToken);
                if (token.ExpirationDate.HasValue && DateTime.Now >= token.ExpirationDate.Value.ToLocalTimeSafe())
                {
                    Logger.OAuth.ErrorFormat(
                        "OAuth access token {0} rejected because it expired at {1}, and it is now {2}.",
                        token.Token,
                        token.ExpirationDate.Value,
                        DateTime.Now);
                    ErrorUtilities.ThrowProtocol(OAuthStrings.TokenNotFound);
                }
            } catch (KeyNotFoundException ex) {
                throw ErrorUtilities.Wrap(ex, OAuthStrings.TokenNotFound);
            }
        }
		/// <summary>
		/// Initializes a new instance of the <see cref="OAuth1Principal"/> class.
		/// </summary>
		/// <param name="token">The access token.</param>
		internal OAuth1Principal(IServiceProviderAccessToken token)
			: base(token.Username, token.Roles) {
			Requires.NotNull(token, "token");

			this.AccessToken = token.Token;
		}