示例#1
0
 public void HandleRequestTokenGrant(QueryParameters responseCollection)
 {
     if (responseCollection.HasName("oauth_token_secret"))
     {
         ConnectionToken.RequestToken = responseCollection["oauth_token"];
         ConnectionToken.TokenSecret  = responseCollection["oauth_token_secret"];
         ConnectionToken.ResponseCollection.AddRange(responseCollection, false);
         logger.Info("Request Token successfully received");
     }
     else
     {
         logger.Error(ErrorMessages.RequestTokenResponseInvalid(responseCollection));
         throw new OAuthException(ErrorMessages.RequestTokenResponseInvalid(responseCollection));
     }
 }
        public void HandleRequestToken(QueryParameters responseCollection)
        {
            //In Hybrid protocol, OAuth may not be necessary. In such case flow ends
            //But some providers may have scope black as scope is defined at provider directly (like Yahoo)

            if (responseCollection.HasName("openid.mode"))
            {
                if (responseCollection["openid.mode"].Contains("cancel"))
                {
                    throw new UserDeniedPermissionException(provider.ProviderType);
                }
            }

            if (!string.IsNullOrEmpty(provider.GetScope()) || provider.IsScopeDefinedAtProvider)
            {
                if (responseCollection.HasName("openid.oauth.request_token"))
                {
                    ConnectionToken.RequestToken = responseCollection["openid.oauth.request_token"];
                }
                else if (responseCollection.HasName("openid.ext2.request_token"))
                {
                    ConnectionToken.RequestToken = responseCollection["openid.ext2.request_token"];
                }
                else
                {
                    logger.Error(ErrorMessages.RequestTokenResponseInvalid(responseCollection));
                    throw new OAuthException(ErrorMessages.RequestTokenResponseInvalid(responseCollection));
                }
            }
            QueryParameters openIDValues = new QueryParameters();

            if (responseCollection.HasName("openid.ns.ext1"))
            {
                if (responseCollection.HasName("openid.ext1.value.email"))
                {
                    openIDValues.Add(new QueryParameter("openid.ext1.value.email", responseCollection["openid.ext1.value.email"]));
                }
                if (responseCollection.HasName("openid.ext1.value.firstname"))
                {
                    openIDValues.Add(new QueryParameter("openid.ext1.value.firstname", responseCollection["openid.ext1.value.firstname"]));
                }
                if (responseCollection.HasName("openid.ext1.value.lastname"))
                {
                    openIDValues.Add(new QueryParameter("openid.ext1.value.lastname", responseCollection["openid.ext1.value.lastname"]));
                }
                if (responseCollection.HasName("openid.ext1.value.language"))
                {
                    openIDValues.Add(new QueryParameter("openid.ext1.value.language", responseCollection["openid.ext1.value.language"]));
                }
                if (responseCollection.HasName("openid.ext1.value.country"))
                {
                    openIDValues.Add(new QueryParameter("openid.ext1.value.country", responseCollection["openid.ext1.value.country"]));
                }
                if (responseCollection.HasName("openid.identity"))
                {
                    openIDValues.Add(new QueryParameter("openid.identity", responseCollection["openid.identity"]));
                }
                ConnectionToken.ResponseCollection.AddRange(openIDValues, true);
            }
            else if (responseCollection.HasName("openid.ns.ax"))
            {
                if (responseCollection.HasName("openid.ax.value.email"))
                {
                    openIDValues.Add(new QueryParameter("openid.ax.value.email", responseCollection["openid.ax.value.email"]));
                }
                if (responseCollection.HasName("openid.ax.value.firstname"))
                {
                    openIDValues.Add(new QueryParameter("openid.ax.value.firstname", responseCollection["openid.ax.value.firstname"]));
                }
                if (responseCollection.HasName("openid.ax.value.lastname"))
                {
                    openIDValues.Add(new QueryParameter("openid.ax.value.lastname", responseCollection["openid.ax.value.lastname"]));
                }
                if (responseCollection.HasName("openid.ax.value.language"))
                {
                    openIDValues.Add(new QueryParameter("openid.ax.value.language", responseCollection["openid.ax.value.language"]));
                }
                if (responseCollection.HasName("openid.ax.value.country"))
                {
                    openIDValues.Add(new QueryParameter("openid.ax.value.country", responseCollection["openid.ax.value.country"]));
                }
                ConnectionToken.ResponseCollection.AddRange(openIDValues, true);
            }
            logger.Info("User successfully logged in and returned with Authorization Token");
        }