Beispiel #1
0
        public RequestToken GetRequestToken(Uri callbackUri)
        {
            IConsumerRequest request = Request()
                                       .ForMethod("GET")
                                       .AlterContext(context => context.CallbackUrl = (callbackUri == null) ? "oob" : callbackUri.ToString())
                                       .AlterContext(context => context.Token       = null)
                                       .ForUri(ConsumerContext.RequestTokenUri)
                                       .SignWithoutToken();

            var results = request.Select(collection =>
                                         new
            {
                ConsumerContext.ConsumerKey,
                Token            = ParseResponseParameter(collection, Parameters.OAuth_Token),
                TokenSecret      = ParseResponseParameter(collection, Parameters.OAuth_Token_Secret),
                CallackConfirmed = WasCallbackConfimed(collection)
            });

            if (!results.CallackConfirmed && CallbackMustBeConfirmed)
            {
                throw Error.CallbackWasNotConfirmed();
            }

            var requestToken = new RequestToken
            {
                ConsumerKey = results.ConsumerKey,
                Token       = results.Token,
                TokenSecret = results.TokenSecret
            };

            TokenRepository.SaveRequestToken(requestToken);

            return(requestToken);
        }