Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Project doest not build with payload-plugin-oauth(^0.3.1) #9

Open
rohitttttt opened this issue Jul 19, 2023 · 4 comments
Open

Project doest not build with payload-plugin-oauth(^0.3.1) #9

rohitttttt opened this issue Jul 19, 2023 · 4 comments

Comments

@rohitttttt
Copy link

rohitttttt commented Jul 19, 2023

Payload does not build with payload-plugin-oauth.

Using below code in payloadconfig.ts

export default buildConfig({
serverURL: process.env.SERVER_URL,//'http://localhost:3000',
admin: {
user: Users.slug,
},
plugins: [
// Replace this plugin with our Custom Plugin for Authentication..
oAuthPlugin({
clientID: process.env.CLIENT_ID,
clientSecret: process.env.CLIENT_SECRET,
authorizationURL: ${process.env.OAUTH_SERVER}/oauth2/authorize,
tokenURL: ${process.env.OAUTH_SERVER}/oauth2/token,
callbackURL: ${process.env.SERVER_URL}/oauth2/callback,
async userinfo(accessToken) {
console.log('inside user info');
const userDetailToken = decodeToken(accessToken);
if(userDetailToken && userDetailToken.unique_name && userDetailToken?.name){
return {
sub: userDetailToken?.oid || 'test',
name: userDetailToken?.name || userDetailToken?.given_name,
email: userDetailToken?.unique_name || userDetailToken?.upn,

    }
  }
  },
}),

],
collections: [TodoLists, Users],
typescript: {
outputFile: path.resolve(__dirname, 'payload-types.ts'),
},
graphQL: {
schemaOutputFile: path.resolve(__dirname, 'generated-schema.graphql'),
},
})

Getting 2 errors.
1)ClientID is not able to found in oauth plugin. For work around i have downloaded the code from github and added missing types in types.ts file and this issue got fixed but again when i ran npm run build it got stuck.
image

2)In oauth Plugin application is not able to pick the value from env file during npm run build. To fix this issue i have passed the hardcoded value then after that my npm run build got stuck. It seems there is issue with this library when i am building my payload cms project.

image
image

@rohitttttt rohitttttt changed the title Project doest not build with payload-plugin-oauth Project doest not build with payload-plugin-oauth(^0.3.1) Jul 19, 2023
@thgh
Copy link
Owner

thgh commented Jul 21, 2023

  1. looks like @types/passport-oauth2 need to be added to dependencies instead of devDependencies

  2. it says that "undefined/oauth2/callback" is not a valid URL, this plugin doesn't know it's in build mode so expects a valid URL. You could set a fallback like this:

const fallback = 'http://fallback'
...
 oAuthPlugin({
      clientID: process.env.CLIENT_ID,
      clientSecret: process.env.CLIENT_SECRET,
      authorizationURL: `${process.env.OAUTH_SERVER || fallback}/oauth2/authorize`,
      tokenURL: `${process.env.OAUTH_SERVER || fallback}/oauth2/token`,
      callbackURL: `${process.env.SERVER_URL || fallback}/oauth2/callback`,
      async userinfo(accessToken) {
        console.log('inside user info')
        const userDetailToken = decodeToken(accessToken)
        if (
          userDetailToken &&
          userDetailToken.unique_name &&
          userDetailToken?.name
        ) {
          return {
            sub: userDetailToken?.oid || 'test',
            name: userDetailToken?.name || userDetailToken?.given_name,
            email: userDetailToken?.unique_name || userDetailToken?.upn,
          }
        }
      },
    })

@rohitttttt
Copy link
Author

rohitttttt commented Jul 24, 2023

@thgh: I have added the fallback but main problem is with npm run build. I have added the @types/passport-oauth2 in dependency but still build is getting stuck.. Please find below attached screen shot for your reference. If i remove the plugin then try to run npm run build its working fine.
image

@thgh
Copy link
Owner

thgh commented Jul 31, 2023

Could you make a repository to reproduce this issue?

@tyteen4a03
Copy link

Can confirm this is an error still.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants