Skip to content

Commit cf47841

Browse files
authored
Merge pull request #5903 from FlowFuse/direct-sso-login
Allow Direct SSO login
2 parents dcaa76b + 05edf1f commit cf47841

6 files changed

Lines changed: 66 additions & 2 deletions

File tree

docs/admin/sso/saml.md

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -181,6 +181,12 @@ that will be used to identify whether a user is an admin or not.
181181
on the platform. It is *strongly* recommended to have an admin user on the system that is not
182182
managed via SSO to ensure continued access in case of any issues with the SSO provider.
183183

184+
## Direct SSO Login
185+
186+
For Self Hosted users there is an option in the Admin Settings to enable buttons on the login page for each active SAML SSO provider.
187+
188+
These buttons will redirect to the SSO provider rather than requiring users to enter and email address in the username field to select the correct provider.
189+
184190
## Providers
185191

186192
The following is a non-exhaustive list of the providers that are known to work

forge/ee/routes/sso/auth.js

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -68,6 +68,20 @@ module.exports = fp(async function (app, opts) {
6868
done(new Error(`No matching SAML provider for email ${request.query.u}`))
6969
return
7070
}
71+
} else if (request.query.p) {
72+
const providerId = request.query.p
73+
const opts = await app.sso.getProviderOptions(providerId)
74+
if (opts) {
75+
request.query.RelayState = JSON.stringify({
76+
provider: providerId,
77+
redirectTo: decodeURIComponent(request.query.r || '/')
78+
})
79+
done(null, opts)
80+
return
81+
} else {
82+
done(new Error(`SAML provider for id ${request.query.p} not found`))
83+
return
84+
}
7185
}
7286
done(new Error('Missing u query parameter'))
7387
}

forge/routes/api/settings.js

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -94,6 +94,9 @@ module.exports = async function (app) {
9494
response['platform:sso:google'] = true
9595
response['platform:sso:google:clientId'] = app.settings.get('platform:sso:google:clientId')
9696
}
97+
if (app.config.features.enabled('sso')) {
98+
response['platform:sso:direct'] = app.settings.get('platform:sso:direct')
99+
}
97100
reply.send(response)
98101
} else {
99102
// This is for an unauthenticated request. Return settings related
@@ -139,6 +142,16 @@ module.exports = async function (app) {
139142
publicSettings['platform:sso:google'] = true
140143
publicSettings['platform:sso:google:clientId'] = app.settings.get('platform:sso:google:clientId')
141144
}
145+
if (app.config.features.enabled('sso') && app.settings.get('platform:sso:direct')) {
146+
const providers = await app.db.models.SAMLProvider.getAll({}, { active: true, type: 'saml' })
147+
const SSOList = providers.providers.map((prov) => {
148+
return {
149+
name: prov.name,
150+
id: prov.hashid
151+
}
152+
})
153+
publicSettings['platform:sso:direct:list'] = SSOList
154+
}
142155

143156
reply.send(publicSettings)
144157
}

forge/settings/defaults.js

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -68,5 +68,7 @@ module.exports = {
6868
'team:broker:topics': null,
6969

7070
'platform:sso:google': false, // Is Google SSO enabled?
71-
'platform:sso:google:clientId': null // Client ID for Google SSO
71+
'platform:sso:google:clientId': null, // Client ID for Google SSO
72+
73+
'platform:sso:direct': false
7274
}

frontend/src/pages/Login.vue

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,16 @@
5050
</GoogleLogin>
5151
<span class="ff-error-inline" data-el="errors-googleSSO">{{ errors.googleSSO }}</span>
5252
</template>
53+
<template v-if="directSSOEnabled">
54+
<hr class="mb-4">
55+
<ul>
56+
<li v-for="{name, id} in settings['platform:sso:direct:list']" :key="id">
57+
<ff-button kind="secondary" :data-action="`direct-sso-${id}`" @click="directSSO(id)">
58+
<span>SIGN IN WITH {{ name.toUpperCase() }}</span>
59+
</ff-button>
60+
</li>
61+
</ul>
62+
</template>
5363
</div>
5464
</template>
5565
<template v-else>
@@ -118,6 +128,11 @@ export default {
118128
},
119129
googleSSOEnabled () {
120130
return this.settings['platform:sso:google'] && this.settings['platform:sso:google:clientId']
131+
},
132+
directSSOEnabled () {
133+
return !!this.settings['platform:sso:direct:list'] &&
134+
Array.isArray(this.settings['platform:sso:direct:list']) &&
135+
this.settings['platform:sso:direct:list'].length >= 1
121136
}
122137
},
123138
watch: {
@@ -229,6 +244,9 @@ export default {
229244
// Handle error response - not sure what this will look like yet
230245
console.error(result)
231246
}
247+
},
248+
async directSSO (id) {
249+
window.location = `/ee/sso/login?p=${id}${this.$route.query.r ? `&r=${this.$route.query.r}` : ''}`
232250
}
233251
}
234252
}

frontend/src/pages/admin/Settings/General.vue

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -189,6 +189,16 @@
189189
</FormRow>
190190
</template>
191191

192+
<template v-if="ssoEnabled">
193+
<FormHeading>Direct SSO Login</FormHeading>
194+
<FormRow v-model="input['platform:sso:direct']" type="checkbox" data-el="direct-sso">
195+
Show buttons on Login page to jump directly to a SAML SSO provider
196+
<template #description>
197+
Allows bypassing email matching for SAML SSO logins. Read more about how to setup SAML SSO <a class="forge-link" href="https://flowfuse.com/docs/admin/sso/saml/" target="_blank">here</a>
198+
</template>
199+
</FormRow>
200+
</template>
201+
192202
<div class="pt-8">
193203
<ff-button :disabled="!saveEnabled" data-action="save-settings" @click="saveChanges">Save settings</ff-button>
194204
</div>
@@ -227,7 +237,8 @@ const validSettings = [
227237
'branding:account:signUpLeftBanner',
228238
'platform:stats:token',
229239
'platform:sso:google',
230-
'platform:sso:google:clientId'
240+
'platform:sso:google:clientId',
241+
'platform:sso:direct'
231242
]
232243
233244
export default {

0 commit comments

Comments
 (0)