2016-04-28 4 views
18

मैंने अपने रिएक्ट-रेडक्स ऐप पर 2 रूट बनाए हैं। मैंने पहले ही होमपेज और कॉलबैक यूआरएल के साथ जिथब एप्लिकेशन सेटिंग्स को जोड़ा है।गीथूब ओथ के साथ एक्सिस कॉरस मुद्दा टोकन तक पहुंच नहीं रहा

1. जब आप इस मार्ग मारा: https://reduxapp.herokuapp.com/signin आप Github लॉगिन बटन पर क्लिक करें, ==>githubGeturi

2. Github एक कोड https://reduxapp.herokuapp.com/auth/callback?code=9536286a59228e7784a1 और githubSendCode ('9536286a59228e7784a1 के साथ वापस आ पुनर्निर्देश ') कार्रवाई ट्रिगर की गई है

आप नेटवर्क कॉल में देख सकते हैं विकल्प कॉल के माध्यम से चला जाता है, लेकिन पोस्ट कॉल कभी नहीं होता है।

XMLHttpRequest cannot load https://github.com/login/oauth/access_token?client_id=32b70bf671e04762b26c&…_secret=5851623d94887db7612d4c9bc689310b9d53284b&code=9536286a59228e7784a1. Response to preflight request doesn't pass access control check: No 'Access-Control-Allow-Origin' header is present on the requested resource. Origin 'https://reduxapp.herokuapp.com' is therefore not allowed access. 

नीचे मेरी कार्रवाई कार्यों है: और आप एक कंसोल त्रुटि मिलती है

const CLIENT_ID = '32b70bf671e04762b26c'; 
const CLIENT_SECRET = '5851623d94887db7612d4c9bc689310b9d53284b'; 
const ROOT_URL = window.location.origin; 
const REDIRECT_URL = `${ROOT_URL}/auth/callback`; 
const AUTHORIZE_URL = 'https://github.com/login/oauth/authorize'; 
const ACCESS_TOKEN_URL = 'https://github.com/login/oauth/access_token'; 
const STATE = _.random(10000); 

export function githubGeturi() { 
    const GITHUB_URL = `${AUTHORIZE_URL}?client_id=${CLIENT_ID}&scope=user,public_repo&redirect_uri=${REDIRECT_URL}`; 

    return (dispatch) => dispatch(signinUrl(GITHUB_URL)); 
} 

export function githubSendCode(code) { 
    const GITHUB_URL = `${ACCESS_TOKEN_URL}?client_id=${CLIENT_ID}&client_secret=${CLIENT_SECRET}&code=${code}`; 

    axios.defaults.headers.post['Access-Control-Allow-Origin'] = '*'; 
    const axiosPost = axios.post(
    GITHUB_URL, 
    { 
    headers: { 
     'Content-Type': 'application/x-www-form-urlencoded', 
     'Accept': 'text/json' 
    } 
    }); 

    return (dispatch) => { 
    dispatch(signinRequest()); 
    return axiosPost 
     .then(
     success => dispatch(signinSuccess(success)), 
     error => dispatch(signinError(error)) 
    ); 
    }; 
} 

======== केवल संभव तरीके से मैंने पाया सर्वर के साथ पोस्ट कॉल करने है । आप यहाँ पूरे समाधान देख सकते हैं: https://github.com/steelx/ReduxWeatherApp/commit/6215634ca543a4760ea96397fe31b61f22184d91

+0

क्या यह इस SO प्रश्न का डुप्लिकेट नहीं है? http://stackoverflow.com/questions/14705726/github-api-and-access-control-allow-origin – Clarkie

+0

यह ओथ एपीआई मुद्दा – STEEL

उत्तर

5

ऐसा लगता है आपके

अपने उदाहरण मुझे लगता है कि विकल्प देखें विधि कॉल के विफल होने पर जावास्क्रिप्ट

https://github.com/isaacs/github/issues/330

के माध्यम से है कि अंत बिंदु करने के लिए एक कॉल नहीं कर सकते, और ऐसा इसलिए है क्योंकि अक्षस ऐसा करता है जब आप अनुरोध करने के लिए अतिरिक्त शीर्षलेख जोड़ते हैं, लेकिन POST कॉल भी विफल रहता है।

आप अपने सर्वर पर अपने ऐप और गिथब के बीच एक प्रॉक्सी सेट कर सकते हैं जो आपके अनुरोधों और प्रतिक्रिया के साथ जवाबों को आगे बढ़ाता है।

+0

लगता है कि वे वास्तविक वेब प्रवाह का समर्थन नहीं करते हैं। – STEEL

+1

@STEEL हाँ और यह बहुत ही बेवकूफ – Burimi

+0

स्थानीय प्रॉक्सी सर्वर का उपयोग कर, गीथब के साथ AJAX कॉल करने के लिए समाधान है। – STEEL

संबंधित मुद्दे