Steps to use this snippet
- Run
requestAccessToken
function either by importing it from this utility or using the window.requestAccessToken
in your browser console passing your clientId you obtained from imgur to it.
It will redirect user to the imgur and authenticate them.
window.requestAccessToken(myClientId);
- Upon finishing authentication, imgur will redirect users back to your application. please make sure you have correct redirectUrl set in the imgur configs. Go to this link: (https://imgur.com/account/settings/apps)[https://imgur.com/account/settings/apps] and click on edit beneath the redirect column. set your redirect url to something like:
http://localhost:3000/oauth-callback
- import
OAuthCallback
from this package and mount it on the endpoint you've set in the previous step. The following snippet is for the url in previous step:
<Route path="/oauth-callback" exact element={<OAuthCallback />} />
- (Optional) You can pass callbacks to
OAuthCallback
to navigate user away upon finishing authentication:
<Route
path="/oauth-callback"
exact
element={
<OAuthCallback onAuthenticationSucceed={() => history.replace('/')} />
}
/>