remix-auth-github icon indicating copy to clipboard operation
remix-auth-github copied to clipboard

[v2] Missing or invalid 'expires_in' field

Open JoseLion opened this issue 1 year ago • 2 comments

After updating to v2 I'm getting a 500 - Internal Server Error on the callback with the following:

Unexpected Server Error

Error: Missing or invalid 'expires_in' field

I'm unsure if I'm missing something or need some additional configuration to upgrade to v2, but I think the problem might be related to https://github.com/sergiodxa/remix-auth-oauth2/pull/116.

Here's the options object and the cookie in case it's helpful:

const gitHubOptions: GitHubStrategyOptions = {
  clientId: process.env.GITHUB_CLIENT_ID,
  clientSecret: process.env.GITHUB_CLIENT_SECRET,
  redirectURI: `${process.env.HOST}${"/auth/github/callback"}`,
  scopes: ["user:email"],
};

const { protocol } = new URL(process.env.HOST);

export const cookie = createCookie("SESSION", {
  httpOnly: protocol === "https:",
  maxAge: Duration.fromObject({ days: 7 }).shiftTo("seconds").seconds,
  path: "/",
  sameSite: "lax",
  secrets: ["xxxxx"],
  secure: protocol === "https:",
});

Let me know if I can help in any way. I'll be happy to contribute to this library 🙂

JoseLion avatar Aug 21 '24 17:08 JoseLion

Getting the same error, github no longer authenticates.

This comes back encoded in the _session cookie:

"__flash_auth:error__": {
    "message": "Missing or invalid 'expires_in' field"
  }

alindsay55661 avatar Aug 22 '24 04:08 alindsay55661

Maybe related to this also: https://github.com/sergiodxa/remix-auth-github/discussions/39

caprica avatar Aug 22 '24 12:08 caprica

I ran into the same issue today and after diving deep into my node_modules (😅), I figured what is going on here.

GitHub doesn't provide the expires_in attribute when you didn't activate the "User-to-server token expiration" feature. This feature is not available in OAuth apps though.

Instead, you have to create a GitHub App and explicitly activate the "User-to-server token expiration" feature.

CleanShot 2024-09-24 at 08 45 46@2x

akoenig avatar Sep 24 '24 06:09 akoenig

The latest version gives you the OAuth2Tokens object directly and you can read the expires_in handling possible missing field.

sergiodxa avatar Nov 27 '24 06:11 sergiodxa