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

Self hosted: ​Google login redirects to app.affine.com? #6886

Open
1 task done
dennorske opened this issue May 11, 2024 · 9 comments
Open
1 task done

Self hosted: ​Google login redirects to app.affine.com? #6886

dennorske opened this issue May 11, 2024 · 9 comments

Comments

@dennorske
Copy link

dennorske commented May 11, 2024

What happened?

Setting Google Client ID and Secret allows for the sign-in to work, but it redirects users to app.affine.pro and not back to my own instance notes.example.com.

Can the redirect URI be overridden somewhere? Relevant snippet i found was this:

const redirectUri = 'https://affine.pro/client/auth-callback';

Client that logs in to my instance via google, is sent to the following URL:
https://accounts.google.com/o/oauth2/v2/auth/oauthchooseaccount?client_id=[redacted]&redirect_uri=https%3A%2F%2Fapp.affine.pro%2Foauth%2Fcallback&response_type=code&scope=openid%20email%20profile&prompt=select_account&access_type=offline&state=ea928a41-f952-45b9-94bd-371b457602aa&service=lso&o2v=2&ddm=0&flowName=GeneralOAuthFlow

Pay extra attention to "redirect_uri".

Possibly related to #6141?

I am also overriding the environment variable AFFINE.host with my own domain.

I have attached a screenshot from my browser network log, it seems to attempt logging in to the public cloud instance;
image

Distribution version

Linux

What browsers are you seeing the problem on if you're using web version?

No response

Are you self-hosting?

  • Yes

Relevant log output

There is no relevant output.

Anything else?

No response

@affine-issue-bot
Copy link

affine-issue-bot bot commented May 11, 2024

Issue Status: *Waiting for Info

*Waiting for Info

We’ve requested additional information from the person who created the issue and are waiting for them to get back to us.

This is an automatic reply by the bot.

@EYHN
Copy link
Member

EYHN commented May 12, 2024

Please provide the config output when the selfhost server starts, let us check whether your config is correct。

@dennorske
Copy link
Author

dennorske commented May 12, 2024

I will attach the startup logs from docker-compose, and my configs:

Docker Compose logs
affine_selfhosted  | running predeploy script.
affine_selfhosted  | yarn run v1.22.19
affine_selfhosted  | $ yarn prisma migrate deploy && node --import ./scripts/register.js ./dist/data/index.js run
affine_selfhosted  | $ /app/node_modules/.bin/prisma migrate deploy
affine_selfhosted  | Prisma schema loaded from schema.prisma
affine_selfhosted  | Datasource "db": PostgreSQL database "affine", schema "public" at "postgres:5432"
affine_selfhosted  | 
affine_selfhosted  | 30 migrations found in prisma/migrations
affine_selfhosted  | 
affine_selfhosted  | 
affine_selfhosted  | No pending migrations to apply.
affine_selfhosted  | (node:150) ExperimentalWarning: Importing JSON modules is an experimental feature and might change at any time
affine_selfhosted  | (Use `node --trace-warnings ...` to show where the warning was created)
affine_selfhosted  | [Nest] 150  - 05/12/2024, 10:16:52 AM     LOG [NestFactory] Starting Nest application...
affine_selfhosted  | [Nest] 150  - 05/12/2024, 10:16:52 AM     LOG [InstanceLoader] CommandRootModule dependencies initialized +23ms
affine_selfhosted  | [Nest] 150  - 05/12/2024, 10:16:52 AM     LOG [InstanceLoader] ConfigModule dependencies initialized +0ms
affine_selfhosted  | [Nest] 150  - 05/12/2024, 10:16:52 AM     LOG [InstanceLoader] AppModule dependencies initialized +0ms
affine_selfhosted  | [Nest] 150  - 05/12/2024, 10:16:52 AM     LOG [InstanceLoader] PrismaModule dependencies initialized +0ms
affine_selfhosted  | [Nest] 150  - 05/12/2024, 10:16:52 AM     LOG [InstanceLoader] WebSocketModule dependencies initialized +0ms
affine_selfhosted  | [Nest] 150  - 05/12/2024, 10:16:52 AM     LOG [InstanceLoader] SyncModule dependencies initialized +0ms
affine_selfhosted  | [Nest] 150  - 05/12/2024, 10:16:52 AM     LOG [InstanceLoader] ServerConfigModule dependencies initialized +0ms
affine_selfhosted  | [Nest] 150  - 05/12/2024, 10:16:52 AM     LOG [InstanceLoader] GqlModule dependencies initialized +0ms
affine_selfhosted  | [Nest] 150  - 05/12/2024, 10:16:52 AM     LOG [InstanceLoader] CacheModule dependencies initialized +6ms
affine_selfhosted  | [Nest] 150  - 05/12/2024, 10:16:52 AM     LOG [InstanceLoader] DiscoveryModule dependencies initialized +0ms
affine_selfhosted  | [Nest] 150  - 05/12/2024, 10:16:52 AM     LOG [InstanceLoader] DiscoveryModule dependencies initialized +0ms
affine_selfhosted  | [Nest] 150  - 05/12/2024, 10:16:52 AM     LOG [InstanceLoader] EventModule dependencies initialized +0ms
affine_selfhosted  | [Nest] 150  - 05/12/2024, 10:16:52 AM     LOG [InstanceLoader] MutexModule dependencies initialized +0ms
affine_selfhosted  | [Nest] 150  - 05/12/2024, 10:16:52 AM     LOG [InstanceLoader] MetricsModule dependencies initialized +0ms
affine_selfhosted  | [Nest] 150  - 05/12/2024, 10:16:52 AM     LOG [InstanceLoader] MailerModule dependencies initialized +0ms
affine_selfhosted  | [Nest] 150  - 05/12/2024, 10:16:52 AM     LOG [InstanceLoader] StorageProviderModule dependencies initialized +0ms
affine_selfhosted  | [Nest] 150  - 05/12/2024, 10:16:52 AM     LOG [InstanceLoader] HelpersModule dependencies initialized +0ms
affine_selfhosted  | [Nest] 150  - 05/12/2024, 10:16:52 AM     LOG [InstanceLoader] ServeStaticModule dependencies initialized +1ms
affine_selfhosted  | [Nest] 150  - 05/12/2024, 10:16:52 AM     LOG [InstanceLoader] EventEmitterModule dependencies initialized +0ms
affine_selfhosted  | [Nest] 150  - 05/12/2024, 10:16:52 AM     LOG [InstanceLoader] ScheduleModule dependencies initialized +0ms
affine_selfhosted  | [Nest] 150  - 05/12/2024, 10:16:52 AM     LOG [InstanceLoader] CommandRunnerModule dependencies initialized +0ms
affine_selfhosted  | [Nest] 150  - 05/12/2024, 10:16:52 AM     LOG [InstanceLoader] FeatureModule dependencies initialized +0ms
affine_selfhosted  | [Nest] 150  - 05/12/2024, 10:16:52 AM     LOG [InstanceLoader] StorageModule dependencies initialized +1ms
affine_selfhosted  | [Nest] 150  - 05/12/2024, 10:16:52 AM     LOG [InstanceLoader] MailModule dependencies initialized +0ms
affine_selfhosted  | [Nest] 150  - 05/12/2024, 10:16:52 AM     LOG [InstanceLoader] ThrottlerModule dependencies initialized +0ms
affine_selfhosted  | [Nest] 150  - 05/12/2024, 10:16:52 AM     LOG [InstanceLoader] CliAppModule dependencies initialized +0ms
affine_selfhosted  | [Nest] 150  - 05/12/2024, 10:16:52 AM     LOG [InstanceLoader] GraphQLSchemaBuilderModule dependencies initialized +0ms
affine_selfhosted  | [Nest] 150  - 05/12/2024, 10:16:52 AM     LOG [InstanceLoader] RateLimiterModule dependencies initialized +0ms
affine_selfhosted  | [Nest] 150  - 05/12/2024, 10:16:52 AM     LOG [InstanceLoader] QuotaModule dependencies initialized +0ms
affine_selfhosted  | [Nest] 150  - 05/12/2024, 10:16:52 AM     LOG [InstanceLoader] DocModule dependencies initialized +1ms
affine_selfhosted  | [Nest] 150  - 05/12/2024, 10:16:52 AM     LOG [InstanceLoader] OAuthModule dependencies initialized +0ms
affine_selfhosted  | [Nest] 150  - 05/12/2024, 10:16:52 AM     LOG [InstanceLoader] EventsModule dependencies initialized +0ms
affine_selfhosted  | [Nest] 150  - 05/12/2024, 10:16:52 AM     LOG [InstanceLoader] UserModule dependencies initialized +1ms
affine_selfhosted  | [Nest] 150  - 05/12/2024, 10:16:52 AM     LOG [InstanceLoader] AuthModule dependencies initialized +0ms
affine_selfhosted  | [Nest] 150  - 05/12/2024, 10:16:52 AM     LOG [InstanceLoader] GraphQLModule dependencies initialized +0ms
affine_selfhosted  | [Nest] 150  - 05/12/2024, 10:16:52 AM     LOG [InstanceLoader] WorkspaceModule dependencies initialized +0ms
affine_selfhosted  | [Nest] 150  - 05/12/2024, 10:16:52 AM     LOG [OAuthProvider:google] OAuth provider registered.
affine_selfhosted  | [Nest] 150  - 05/12/2024, 10:16:52 AM     LOG [RunCommand] Done 0 migrations
affine_selfhosted  | Done in 4.18s.
affine_selfhosted  | (node:229) ExperimentalWarning: Importing JSON modules is an experimental feature and might change at any time
affine_selfhosted  | (Use `node --trace-warnings ...` to show where the warning was created)
affine_selfhosted  | [Nest] 229  - 05/12/2024, 10:16:54 AM     LOG [NestFactory] Starting Nest application...
affine_selfhosted  | [Nest] 229  - 05/12/2024, 10:16:54 AM     LOG [InstanceLoader] AppModule dependencies initialized +26ms
affine_selfhosted  | [Nest] 229  - 05/12/2024, 10:16:54 AM     LOG [InstanceLoader] ConfigModule dependencies initialized +0ms
affine_selfhosted  | [Nest] 229  - 05/12/2024, 10:16:54 AM     LOG [InstanceLoader] PrismaModule dependencies initialized +0ms
affine_selfhosted  | [Nest] 229  - 05/12/2024, 10:16:54 AM     LOG [InstanceLoader] WebSocketModule dependencies initialized +0ms
affine_selfhosted  | [Nest] 229  - 05/12/2024, 10:16:54 AM     LOG [InstanceLoader] SyncModule dependencies initialized +0ms
affine_selfhosted  | [Nest] 229  - 05/12/2024, 10:16:54 AM     LOG [InstanceLoader] ServerConfigModule dependencies initialized +0ms
affine_selfhosted  | [Nest] 229  - 05/12/2024, 10:16:54 AM     LOG [InstanceLoader] GqlModule dependencies initialized +0ms
affine_selfhosted  | [Nest] 229  - 05/12/2024, 10:16:54 AM     LOG [InstanceLoader] CacheModule dependencies initialized +5ms
affine_selfhosted  | [Nest] 229  - 05/12/2024, 10:16:54 AM     LOG [InstanceLoader] DiscoveryModule dependencies initialized +0ms
affine_selfhosted  | [Nest] 229  - 05/12/2024, 10:16:54 AM     LOG [InstanceLoader] MetricsModule dependencies initialized +0ms
affine_selfhosted  | [Nest] 229  - 05/12/2024, 10:16:54 AM     LOG [InstanceLoader] MailerModule dependencies initialized +0ms
affine_selfhosted  | [Nest] 229  - 05/12/2024, 10:16:54 AM     LOG [InstanceLoader] StorageProviderModule dependencies initialized +0ms
affine_selfhosted  | [Nest] 229  - 05/12/2024, 10:16:54 AM     LOG [InstanceLoader] HelpersModule dependencies initialized +0ms
affine_selfhosted  | [Nest] 229  - 05/12/2024, 10:16:54 AM     LOG [InstanceLoader] EventModule dependencies initialized +1ms
affine_selfhosted  | [Nest] 229  - 05/12/2024, 10:16:54 AM     LOG [InstanceLoader] MutexModule dependencies initialized +0ms
affine_selfhosted  | [Nest] 229  - 05/12/2024, 10:16:54 AM     LOG [InstanceLoader] ServeStaticModule dependencies initialized +0ms
affine_selfhosted  | [Nest] 229  - 05/12/2024, 10:16:54 AM     LOG [InstanceLoader] EventEmitterModule dependencies initialized +1ms
affine_selfhosted  | [Nest] 229  - 05/12/2024, 10:16:54 AM     LOG [InstanceLoader] ScheduleModule dependencies initialized +0ms
affine_selfhosted  | [Nest] 229  - 05/12/2024, 10:16:54 AM     LOG [InstanceLoader] MailModule dependencies initialized +0ms
affine_selfhosted  | [Nest] 229  - 05/12/2024, 10:16:54 AM     LOG [InstanceLoader] FeatureModule dependencies initialized +0ms
affine_selfhosted  | [Nest] 229  - 05/12/2024, 10:16:54 AM     LOG [InstanceLoader] StorageModule dependencies initialized +0ms
affine_selfhosted  | [Nest] 229  - 05/12/2024, 10:16:54 AM     LOG [InstanceLoader] ThrottlerModule dependencies initialized +0ms
affine_selfhosted  | [Nest] 229  - 05/12/2024, 10:16:54 AM     LOG [InstanceLoader] RateLimiterModule dependencies initialized +1ms
affine_selfhosted  | [Nest] 229  - 05/12/2024, 10:16:54 AM     LOG [InstanceLoader] QuotaModule dependencies initialized +0ms
affine_selfhosted  | [Nest] 229  - 05/12/2024, 10:16:54 AM     LOG [InstanceLoader] GraphQLSchemaBuilderModule dependencies initialized +0ms
affine_selfhosted  | [Nest] 229  - 05/12/2024, 10:16:54 AM     LOG [InstanceLoader] DocModule dependencies initialized +0ms
affine_selfhosted  | [Nest] 229  - 05/12/2024, 10:16:54 AM     LOG [InstanceLoader] OAuthModule dependencies initialized +0ms
affine_selfhosted  | [Nest] 229  - 05/12/2024, 10:16:54 AM     LOG [InstanceLoader] EventsModule dependencies initialized +0ms
affine_selfhosted  | [Nest] 229  - 05/12/2024, 10:16:54 AM     LOG [InstanceLoader] UserModule dependencies initialized +1ms
affine_selfhosted  | [Nest] 229  - 05/12/2024, 10:16:54 AM     LOG [InstanceLoader] AuthModule dependencies initialized +0ms
affine_selfhosted  | [Nest] 229  - 05/12/2024, 10:16:54 AM     LOG [InstanceLoader] GraphQLModule dependencies initialized +0ms
affine_selfhosted  | [Nest] 229  - 05/12/2024, 10:16:54 AM     LOG [InstanceLoader] WorkspaceModule dependencies initialized +0ms
affine_selfhosted  | [Nest] 229  - 05/12/2024, 10:16:54 AM     LOG [WebSocketsController] EventsGateway subscribed to the "client-handshake-sync" message +8ms
affine_selfhosted  | [Nest] 229  - 05/12/2024, 10:16:54 AM     LOG [WebSocketsController] EventsGateway subscribed to the "client-handshake-awareness" message +0ms
affine_selfhosted  | [Nest] 229  - 05/12/2024, 10:16:54 AM     LOG [WebSocketsController] EventsGateway subscribed to the "client-leave-sync" message +0ms
affine_selfhosted  | [Nest] 229  - 05/12/2024, 10:16:54 AM     LOG [WebSocketsController] EventsGateway subscribed to the "client-leave-awareness" message +0ms
affine_selfhosted  | [Nest] 229  - 05/12/2024, 10:16:54 AM     LOG [WebSocketsController] EventsGateway subscribed to the "client-pre-sync" message +0ms
affine_selfhosted  | [Nest] 229  - 05/12/2024, 10:16:54 AM     LOG [WebSocketsController] EventsGateway subscribed to the "client-update-v2" message +0ms
affine_selfhosted  | [Nest] 229  - 05/12/2024, 10:16:54 AM     LOG [WebSocketsController] EventsGateway subscribed to the "doc-load-v2" message +0ms
affine_selfhosted  | [Nest] 229  - 05/12/2024, 10:16:54 AM     LOG [WebSocketsController] EventsGateway subscribed to the "awareness-init" message +0ms
affine_selfhosted  | [Nest] 229  - 05/12/2024, 10:16:54 AM     LOG [WebSocketsController] EventsGateway subscribed to the "awareness-update" message +0ms
affine_selfhosted  | [Nest] 229  - 05/12/2024, 10:16:54 AM     LOG [RoutesResolver] AuthController {/api/auth}: +1ms
affine_selfhosted  | [Nest] 229  - 05/12/2024, 10:16:54 AM     LOG [RouterExplorer] Mapped {/api/auth/sign-in, POST} route +1ms
affine_selfhosted  | [Nest] 229  - 05/12/2024, 10:16:54 AM     LOG [RouterExplorer] Mapped {/api/auth/sign-out, GET} route +0ms
affine_selfhosted  | [Nest] 229  - 05/12/2024, 10:16:54 AM     LOG [RouterExplorer] Mapped {/api/auth/magic-link, POST} route +1ms
affine_selfhosted  | [Nest] 229  - 05/12/2024, 10:16:54 AM     LOG [RouterExplorer] Mapped {/api/auth/session, GET} route +0ms
affine_selfhosted  | [Nest] 229  - 05/12/2024, 10:16:54 AM     LOG [RouterExplorer] Mapped {/api/auth/sessions, GET} route +0ms
affine_selfhosted  | [Nest] 229  - 05/12/2024, 10:16:54 AM     LOG [RouterExplorer] Mapped {/api/auth/challenge, GET} route +0ms
affine_selfhosted  | [Nest] 229  - 05/12/2024, 10:16:54 AM     LOG [RoutesResolver] UserAvatarController {/api/avatars}: +0ms
affine_selfhosted  | [Nest] 229  - 05/12/2024, 10:16:54 AM     LOG [RouterExplorer] Mapped {/api/avatars/:id, GET} route +0ms
affine_selfhosted  | [Nest] 229  - 05/12/2024, 10:16:54 AM     LOG [RoutesResolver] WorkspacesController {/api/workspaces}: +1ms
affine_selfhosted  | [Nest] 229  - 05/12/2024, 10:16:54 AM     LOG [RouterExplorer] Mapped {/api/workspaces/:id/blobs/:name, GET} route +0ms
affine_selfhosted  | [Nest] 229  - 05/12/2024, 10:16:54 AM     LOG [RouterExplorer] Mapped {/api/workspaces/:id/docs/:guid, GET} route +0ms
affine_selfhosted  | [Nest] 229  - 05/12/2024, 10:16:54 AM     LOG [RouterExplorer] Mapped {/api/workspaces/:id/docs/:guid/histories/:timestamp, GET} route +0ms
affine_selfhosted  | [Nest] 229  - 05/12/2024, 10:16:54 AM     LOG [RoutesResolver] OAuthController {/oauth}: +0ms
affine_selfhosted  | [Nest] 229  - 05/12/2024, 10:16:54 AM     LOG [RouterExplorer] Mapped {/oauth/login, GET} route +1ms
affine_selfhosted  | [Nest] 229  - 05/12/2024, 10:16:54 AM     LOG [RouterExplorer] Mapped {/oauth/callback, GET} route +0ms
affine_selfhosted  | [Nest] 229  - 05/12/2024, 10:16:54 AM     LOG [DocManager] Use Database
affine_selfhosted  | [Nest] 229  - 05/12/2024, 10:16:54 AM     LOG [DocManager] Automation started
affine_selfhosted  | [Nest] 229  - 05/12/2024, 10:16:54 AM     LOG [GraphQLModule] Mapped {/graphql, POST} route +83ms
affine_selfhosted  | [Nest] 229  - 05/12/2024, 10:16:54 AM     LOG [OAuthProvider:google] OAuth provider registered.
affine_selfhosted  | [Nest] 229  - 05/12/2024, 10:16:54 AM     LOG [NestApplication] Nest application successfully started +15ms
affine_selfhosted  | [Nest] 229  - 05/12/2024, 10:16:54 AM     LOG [App] AFFiNE Server is running in [selfhosted] mode
affine_selfhosted  | [Nest] 229  - 05/12/2024, 10:16:54 AM     LOG [App] Listening on http://0.0.0.0:3010
affine_selfhosted  | [Nest] 229  - 05/12/2024, 10:16:54 AM     LOG [App] And the public server should be recognized as https://my.custom.domain
affine.js config
//
// ###############################################################
// ##                AFFiNE Configuration System                ##
// ###############################################################

// > Configurations merge order
//   1. load environment variables (`.env` if provided, and from system)
//   2. load `src/fundamentals/config/default.ts` for all default settings
//   3. apply `./affine.ts` patches (this file)
//   4. apply `./affine.env.ts` patches

AFFiNE.serverName = 'Shokis notes';
//
// /* Whether the server is deployed behind a HTTPS proxied environment */
AFFiNE.https = true;
// /* Domain of your server that your server will be available at */
AFFiNE.host = 'my.custom.domain';
// /* The local port of your server that will listen on */
AFFiNE.port = 3010;

AFFiNE.metrics.enabled = true;

AFFiNE.auth.allowSignup = true;

AFFiNE.plugins.use('oauth', {
   providers: {
     google: {
       clientId: '[redacted].apps.googleusercontent.com',
       clientSecret: 'G**SPX-***[redacted]***',
       args: {
         // See https://developers.google.com/identity/protocols/oauth2
         scope: 'openid email profile',
         promot: 'select_account',
         access_type: 'offline',
       },
     },
   },
});
my .env
AFFINE_ADMIN_EMAIL=[redacted]
AFFINE_ADMIN_PASSWORD=[redacted]

#email
MAILER_HOST=smtp.gmail.com
MAILER_PASSWORD=[redacted]
MAILER_PORT=465
MAILER_SECURE=true
MAILER_SENDER=AFFiNE <[redacted]>
MAILER_USER=[redacted]

@dennorske
Copy link
Author

Are there any other configs or logs you will need to help triage the problem?

@darkskygit
Copy link
Member

seems you not set AFFINE_SERVER_HOST yet?

@Mendes11
Copy link

Having the same issue here, the redirect url is hardcoded. I set AFFINE_SERVER_HOST btw

@dennorske
Copy link
Author

seems you not set AFFINE_SERVER_HOST yet?

I have, just removed original value in the affine.js config. I assume affine.host is the same as AFFINE_SERVER_HOST?

@dennorske
Copy link
Author

To avoid that my assumptions is slowing this down, I have also tried to set AFFINE_SERVER_HOST in my environment, and it still has the same issue, no change.

@darkskygit
Copy link
Member

To avoid that my assumptions is slowing this down, I have also tried to set AFFINE_SERVER_HOST in my environment, and it still has the same issue, no change.

I upgraded the container in my nas to the latest version today and reproduced this problem. I will troubleshoot this problem tomorrow

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

No branches or pull requests

4 participants