Compare commits

...

7 Commits

Author SHA1 Message Date
Balázs Orbán
810d02e671 fix(deps): upgrade to latest preact-render-to-string (#1475) 2021-03-08 10:39:13 +01:00
Valentin Hervieu
e5535734f8 fix(client): set useSession loading state correctly (#1468)
This is fixing #1467.

The issue was due to doing the `setLoading(false)` in the finally:  as we can do an early return [here](a7e08e2a32/src/client/index.js (L100-L100)), we would still go to the finally and mark the session as being loaded.

I simply removed the `finally` block to only set the `loading` state to false when:
- the data is ready
- an error occures
2021-03-07 19:11:32 +01:00
Taehwan Noh
ba7aed1057 feat(provider): add Kakao provider (#1459) 2021-03-06 21:52:39 +01:00
Balázs Orbán
a7e08e2a32 fix: make sure useSession populates session correctly (#1462) 2021-03-06 20:02:43 +01:00
mcha
0d13040264 docs(client): fix client.md typos (#1453) 2021-03-06 10:50:29 +01:00
Balázs Orbán
582520f8ef chore: fix typo in feature request template 2021-03-06 00:35:09 +01:00
Sam Bauch
95942519a5 feat(provider): add Osso SAML provider (#1448)
Co-authored-by: @sbauch
2021-03-06 00:21:38 +01:00
15 changed files with 135 additions and 17 deletions

View File

@@ -9,7 +9,7 @@ assignees: ''
A clear and concise description of the feature being proposed.
**Purpose of proposed feature**
A clear and concise description description of why this feature is necessary and what problems it solves.
A clear and concise description of why this feature is necessary and what problems it solves.
**Detail about proposed feature**
A detailed description of how the proposal might work (if you have one).

6
package-lock.json generated
View File

@@ -15675,9 +15675,9 @@
"integrity": "sha512-WKrRpCSwL2t3tpOOGhf2WfTpcmbpxaWtDbdJdKdjd0aEiTkvOmS4NBkG6kzlaAHI9AkQ3iVqbFWM3Ei7mZ4o1Q=="
},
"preact-render-to-string": {
"version": "5.1.7",
"resolved": "https://registry.npmjs.org/preact-render-to-string/-/preact-render-to-string-5.1.7.tgz",
"integrity": "sha512-3F4qvUsbiS/ZJ0lOHF+I8aye6x63QSXeOjaATJ6KppJsCUJW9adHa7CbBYX7Ib3DlYDp6PFwfefxK72NKys2sA==",
"version": "5.1.14",
"resolved": "https://registry.npmjs.org/preact-render-to-string/-/preact-render-to-string-5.1.14.tgz",
"integrity": "sha512-xG/spHMnDX1cOOetZiFhljtczYUXqBrhuB+C2H+V0y3fJX8TmZtMrC+5di70y0E9fWAWiQIO5VTCpSDLoRmhzg==",
"requires": {
"pretty-format": "^3.8.0"
}

View File

@@ -50,7 +50,7 @@
"oauth": "^0.9.15",
"pkce-challenge": "^2.1.0",
"preact": "^10.4.1",
"preact-render-to-string": "^5.1.7",
"preact-render-to-string": "^5.1.14",
"querystring": "^0.2.0",
"require_optional": "^1.0.1",
"typeorm": "^0.2.30"

View File

@@ -71,7 +71,12 @@ const SessionContext = createContext()
*/
export function useSession (session) {
const context = useContext(SessionContext)
const [data, setData] = useState(context?.[0] ?? session)
if (context) return context
return _useSessionHook(session)
}
function _useSessionHook (session) {
const [data, setData] = useState(session)
const [loading, setLoading] = useState(!data)
useEffect(() => {
@@ -125,9 +130,9 @@ export function useSession (session) {
__NEXTAUTH._clientSession = newClientSessionData
setData(newClientSessionData)
setLoading(false)
} catch (error) {
logger.error('CLIENT_USE_SESSION_ERROR', error)
} finally {
setLoading(false)
}
}

View File

@@ -19,12 +19,14 @@ import GitLab from './gitlab'
import Google from './google'
import IdentityServer4 from './identity-server4'
import Instagram from './instagram'
import Kakao from './kakao'
import LINE from './line'
import LinkedIn from './linkedin'
import MailRu from './mailru'
import Medium from './medium'
import Netlify from './netlify'
import Okta from './okta'
import Osso from './osso'
import Reddit from './reddit'
import Salesforce from './salesforce'
import Slack from './slack'
@@ -57,12 +59,14 @@ export default {
Google,
IdentityServer4,
Instagram,
Kakao,
LINE,
LinkedIn,
MailRu,
Medium,
Netlify,
Okta,
Osso,
Reddit,
Salesforce,
Slack,

21
src/providers/kakao.js Normal file
View File

@@ -0,0 +1,21 @@
export default (options) => {
return {
id: 'kakao',
name: 'Kakao',
type: 'oauth',
version: '2.0',
params: { grant_type: 'authorization_code' },
accessTokenUrl: 'https://kauth.kakao.com/oauth/token',
authorizationUrl: 'https://kauth.kakao.com/oauth/authorize?response_type=code',
profileUrl: 'https://kapi.kakao.com/v2/user/me',
profile: (profile) => {
return {
id: profile.id,
name: profile.kakao_account?.profile.nickname,
email: profile.kakao_account?.email,
image: profile.kakao_account?.profile.profile_image_url
}
},
...options
}
}

20
src/providers/osso.js Normal file
View File

@@ -0,0 +1,20 @@
export default (options) => {
return {
id: 'osso',
name: 'SAML SSO',
type: 'oauth',
version: '2.0',
params: { grant_type: 'authorization_code' },
accessTokenUrl: `https://${options.domain}/oauth/token`,
authorizationUrl: `https://${options.domain}/oauth/authorize?response_type=code`,
profileUrl: `https://${options.domain}/oauth/me`,
profile: (profile) => {
return {
id: profile.id,
name: profile.name || profile.email,
email: profile.email
}
},
...options
}
}

View File

@@ -1,6 +1,5 @@
// @ts-check
import { h } from 'preact' // eslint-disable-line no-unused-vars
import render from 'preact-render-to-string'
/**
* Renders an error page.
@@ -57,7 +56,7 @@ export default function error ({ baseUrl, basePath, error = 'default', res }) {
res.status(statusCode)
return render(
return (
<div className='error'>
<h1>{heading}</h1>
<div className='message'>{message}</div>

View File

@@ -1,3 +1,4 @@
import renderToString from 'preact-render-to-string'
import signin from './signin'
import signout from './signout'
import verifyRequest from './verify-request'
@@ -10,7 +11,7 @@ export default function renderPage (req, res) {
res.setHeader('Content-Type', 'text/html')
function send ({ html, title }) {
res.send(`<!DOCTYPE html><html lang="en"><head><meta charset="UTF-8"><meta http-equiv="X-UA-Compatible" content="IE=edge"><meta name="viewport" content="width=device-width, initial-scale=1.0"><style>${css()}</style><title>${title}</title></head><body class="__next-auth-theme-${theme}"><div class="page">${html}</div></body></html>`)
res.send(`<!DOCTYPE html><html lang="en"><head><meta charset="UTF-8"><meta http-equiv="X-UA-Compatible" content="IE=edge"><meta name="viewport" content="width=device-width, initial-scale=1.0"><style>${css()}</style><title>${title}</title></head><body class="__next-auth-theme-${theme}"><div class="page">${renderToString(html)}</div></body></html>`)
}
return {

View File

@@ -1,5 +1,4 @@
import { h } from 'preact' // eslint-disable-line no-unused-vars
import render from 'preact-render-to-string'
export default function signin ({ csrfToken, providers, callbackUrl, email, error: errorType }) {
// We only want to render providers
@@ -30,7 +29,7 @@ export default function signin ({ csrfToken, providers, callbackUrl, email, erro
const error = errorType && (errors[errorType] ?? errors.default)
return render(
return (
<div className='signin'>
{error &&
<div className='error'>

View File

@@ -1,8 +1,7 @@
import { h } from 'preact' // eslint-disable-line no-unused-vars
import render from 'preact-render-to-string'
export default function signout ({ baseUrl, basePath, csrfToken }) {
return render(
return (
<div className='signout'>
<h1>Are you sure you want to sign out?</h1>
<form action={`${baseUrl}${basePath}/signout`} method='POST'>

View File

@@ -1,8 +1,7 @@
import { h } from 'preact' // eslint-disable-line no-unused-vars
import render from 'preact-render-to-string'
export default function verifyRequest ({ baseUrl }) {
return render(
return (
<div className='verify-request'>
<h1>Check your email</h1>
<p>A sign in link has been sent to your email address.</p>

View File

@@ -356,7 +356,7 @@ export default function App ({ Component, pageProps }) {
:::note
**These options have no effect on clients that are not signed in.**
Every tab/window maintains it's own copy of the local session state; the session it is not stored in shared storage like localStorage or sessionStorage. Any update in one tab/window triggers a message to other tabs/windows to update their own session state.
Every tab/window maintains its own copy of the local session state; the session is not stored in shared storage like localStorage or sessionStorage. Any update in one tab/window triggers a message to other tabs/windows to update their own session state.
Using low values for `clientMaxAge` or `keepAlive` will increase network traffic and load on authenticated clients and may impact hosting costs and performance.
:::

View File

@@ -0,0 +1,32 @@
---
id: kakao
title: Kakao
---
## Documentation
https://developers.kakao.com/product/kakaoLogin
## Configuration
https://developers.kakao.com/docs/latest/en/kakaologin/common
## Example
```js
import Providers from `next-auth/providers`
...
providers: [
Providers.Kakao({
clientId: process.env.KAKAO_CLIENT_ID,
clientSecret: process.env.KAKAO_CLIENT_SECRET
})
]
...
```
## Instructions
### Configuration
Create a provider and a Kakao application at `https://developers.kakao.com/console/app`. In the settings of the app under Kakao Login, activate web app, change consent items and configure callback URL.

View File

@@ -0,0 +1,39 @@
---
id: osso
title: Osso
---
## Documentation
Osso is an open source service that handles SAML authentication against Identity Providers, normalizes profiles, and makes those profiles available to you in an OAuth 2.0 code grant flow.
If you don't yet have an Osso instance, you can use [Osso's Demo App](https://demo.ossoapp.com) for your testing purposes. For documentation on deploying an Osso instance, see https://ossoapp.com/docs/deploy/overview/
## Configuration
You can configure your OAuth Clients on your Osso Admin UI, i.e. https://demo.ossoapp.com/admin/config - you'll need to get a Client ID and Secret and allow-list your redirect URIs.
[SAML SSO differs a bit from OAuth](https://ossoapp.com/blog/saml-vs-oauth) - for every tenant who wants to sign in to your application using SAML, you and your customer need to perform a multi-step configuration in Osso's Admin UI and the admin dashboard of the tenant's Identity Provider. Osso provides documentation for providers like Okta and OneLogin, cloud-based IDPs who also offer a developer account that's useful for testing. Osso also provides a [Mock IDP](https://idp.ossoapp.com) that you can use for testing without needing to sign up for an Identity Provider service.
See Osso's complete configuration and testing documentation at https://ossoapp.com/docs/configure/overview
## Example
A full example application is available at https://github.com/enterprise-oss/osso-next-auth-example and https://nextjs-demo.ossoapp.com
```js
import Providers from `next-auth/providers`
...
providers: [
Providers.Osso({
clientId: process.env.OSSO_CLIENT_ID,
clientSecret: process.env.OSSO_CLIENT_SECRET,
domain: process.env.OSSO_DOMAIN
})
}
...
```
:::note
`domain` should be the fully qualified domain  e.g. `demo.ossoapp.com`
:::