vosmiic / jellyfin-ani-sync

Synchronize anime watch status between Jellyfin and anime tracking sites.
GNU General Public License v3.0
243 stars 17 forks source link

Getting Unauthorized URL GET /AniSync/authCallback error #25

Closed munit85 closed 2 years ago

munit85 commented 2 years ago

I've been trying to set this up. I've checked test url and got confirmation. I've tried using local IP and my DNS setup. I believe I have my api setup correctly on MAL. I get the following error when trying.

[12:07:43] [ERR] [98] Jellyfin.Server.Middleware.ExceptionMiddleware: Error processing request: Could not retrieve Mal token: Unauthorized - Unauthorized. URL GET /AniSync/authCallback.

When I hit allow on MAL i get a blank page that says "Error processing request."

Any ideas?

vosmiic commented 2 years ago

Could you confirm the URL that you are redirected to from MAL looks correct? Locally it should be http(s)://192.168.X.X:{{Port}}/AniSync/authCallback?code=XXXXXXX If you are going to post the URL you visit please don't post the code value, it will allow others to impersonate you when making API calls

munit85 commented 2 years ago

https://jellyfin.xxxx.com/AniSync/authCallback?code=dxyz... is what it is. obviously i cut out the web address http://192.168.1.3:8096/AniSync/authCallback?code=def5... for local

I've tried a couple browsers and turned off any adblocking etc. I'm sure its just some random weird thing I'm doing incorrectly. Api says its published. I grabbed the id and secret from there.

This is using docker on Unraid or that makes any difference. Using the linuxserver image

vosmiic commented 2 years ago

The URL looks good. I wouldn't have thought using a docker image would effect it. Are you logged into Jellyfin in the browser you are authenticating MAL with? I've never seen an auth error on the Jellyfin side before with the callback, so it might be a bit of back and forth with trying different potential solutions unfortunately

munit85 commented 2 years ago

Yeah I'm logged in. I'll play around with it and see if I get anything to work. Thanks

vosmiic commented 2 years ago

Hmm that is strange. The endpoint isn't protected by any authentication so I'm not sure why you are getting that response.

You could manually set it in the config, but it requires a few extra steps that you may not be comfortable doing. I'll give you a quick run down:

  1. Get to the authCallback page that gives you the error. Note down the code value.
  2. Run the following CURL request:
    curl --location --request POST 'https://myanimelist.net/v1/oauth2/token' \
    --form 'client_id="{{ClientId}}"' \
    --form 'client_secret="{{ClientSecret}}"' \
    --form 'code="{{Code}}"' \
    --form 'grant_type="authorization_code"' \
    --form 'redirect_uri="{{RedirectUrl}}"' \
    --form 'code_verifier="eZBLUX_JPk4~el62z_k3Q4fV5CzCYHoTz4iLKvwJ~9QTsTJNlzwveKCSYCSiSOa5zAm5Zt~cfyVM~3BuO4kQ0iYwCxPoeN0SOmBYR_C.QgnzyYE4KY-xIe4Vy1bf7_B4"'
  3. You should now get back the following JSON:
    {
    "token_type": "Bearer",
    "expires_in": 2592000,
    "access_token": "{{AccessToken}}",
    "refresh_token": "{{RefreshToken}}"
    }
  4. You now need to save this in the plugin config. For me, on Linux via direct install, its '/home/{{User}}/.local/share/jellyfin/plugins/configurations/'. This page should help you find it out for your installation.
  5. Open jellyfin-ani-sync.xml and check for a similar script in the XML file:
    ...
    <UserConfig>
      <UserId>123USERID</UserId>
      <PlanToWatchOnly>true</PlanToWatchOnly>
      <RewatchCompleted>true</RewatchCompleted>
      <UserApiAuth>
        <UserApiAuth>
          <Name>Mal</Name>
          <AccessToken>{{AccessToken}}</AccessToken>
          <RefreshToken>{{RefreshToken}}</RefreshToken>
        </UserApiAuth>
      </UserApiAuth>
    </UserConfig>
    ...
    <currentlyAuthenticatingUser>123USERID</currentlyAuthenticatingUser>
    ...

    Set the AccessToken and RefreshToken values as the values from the CURL response. Note that currentlyAuthenticatingUser and UserId need to match. If you don't see a UserConfig object with the right UserId, go back to Jellyfin and change some user options (only change anime in plan to watch, libraries to check etc.) and then click save. Check the XML file again and it will be there.

  6. Save the XML file and reboot the Jellyfin server. Test out the authentication for that user. Nasty way of doing it but it will work. Depends how desparate you are to get this working haha.
munit85 commented 2 years ago

Welp i solved it I guess. I opened up that jellyfin-ani-sync.xml file and noticed the <ClientSecret> 120938asjasdik2309</ClientSecret> line had a big space before the client secret actually started. So i went in and got rid of that space and ran the authorization and it worked. So for whatever reason it had an extra spacing in there and removing it fixed it. Hooray

// working great with "Ticking watched updates providers?" checked and "Only change anime in Plan To Watch?" unchecked