-
Hello, I am using microsoft strategy. I have two domains, the standard const authenticator = new Authenticator(sessionServer.sessionStorage)
const setupAuth = async (request: Request): Promise<void> => {
const urlParser = new URL(request.url)
const domain = urlParser.hostname
let baseUrl = config.get('server.baseUrl')
if (process.env.NODE_ENV === 'production') {
baseUrl = domain.includes('wwww')
? config.get('server.baseUrl')
: config.get('server.bareUrl')
}
const microsoftStrategy = new MicrosoftStrategy(
{
clientId: String(config.get('sso.microsoft.client_id')),
clientSecret: String(config.get('sso.microsoft.client_secret')),
redirectUri: `${baseUrl}/auth/microsoft/callback`,
tenantId: String(config.get('sso.microsoft.tenant_id')),
scope: 'openid profile email',
prompt: 'select_account',
},
async ({ profile }): Promise<User | void> => {
//create user
},
)
authenticator.use(microsoftStrategy)
}
export { authenticator, setupAuth } In export const loader = () => redirect(/signin)
export const action = async ({ request }: ActionArgs) => {
await setupAuth(request)
return authenticator.authenticate('microsoft', request)
} In export const loader = async ({ request }: LoaderArgs) => {
await setupAuth(request)
const user = (await authenticator.authenticate(
'microsoft',
request,
{},
))
if (user) {
return sessionServer.createUserSession({
request,
userId: user.id,
remember: false,
redirectTo: '/',
})
}
return redirect(/signin)
} I am also setting maxAge when the user is authenticated: this.sessionStorage = createCookieSessionStorage({
cookie: {
name: '__session',
httpOnly: true,
path: '/',
sameSite: 'lax',
secrets: ['somesecret'],
secure: process.env.NODE_ENV === 'production',
maxAge: 60 * 60 * 24, // 24 hours
},
}) When using the bare domain, it works. But when using the base domain with |
Beta Was this translation helpful? Give feedback.
Replies: 2 comments 2 replies
-
Did you ever figure this out? |
Beta Was this translation helpful? Give feedback.
-
The recommended solution for this is to create a function that returns the authenticator and setup strategies, this function can receive the request or any other argument you may need to setup the redirect uri. export function createAuthenticator(request: Request) {
let url = new URL(request.url)
let auth = new Authenticator()
auth.use(new MyStrategy({ redirectURI: new URL(url, "/callback").toString() }))
return auth
} |
Beta Was this translation helpful? Give feedback.
The recommended solution for this is to create a function that returns the authenticator and setup strategies, this function can receive the request or any other argument you may need to setup the redirect uri.