yaroslawww/nova-external-login

Laravel Nova resource tool that allows a user or other resource to log into an external control panel or application.

1.0.0 2021-05-28 21:08 UTC

This package is auto-updated.

Last update: 2024-03-29 04:39:38 UTC


README

Laravel Nova resource tool that allows a user or other resource to log into an external control panel or application.

external-login

Installation

composer require yaroslawww/nova-external-login

Usage

Nova Part

ExternalLogin::make()
     ->setUniqueKey('ads-dashboard') // in case if you want add two different logins to same resource
     ->buttonTitle('Login to SPA')
     ->iframePath('/login-as')
     ->redirectPath('/home')
     ->postUrl('https://spa.mydomain.com')
     ->loginUsing(function (NovaRequest $request) {
         return Response::json([
         'data' => [
                 'access_token' => thereFunctionWillGenerateAndReturnToken($request),
                 // other params if need
             ]
         ], 201);
     }),

SPA part

File should contain js something like this

export default Vue.extend({
    // ...
    created() {
        window.addEventListener('message', (event) => {
            if (event.origin === this.$config.adminURL) {
                if (event.data && event.data.access_token) {
                    this.$store.dispatch('auth/setToken', event.data.access_token)
                    setTimeout(() => {
                        this.$store
                            .dispatch('auth/getProfile')
                            .then((response) => {
                                console.warn(response)
                                // Some data
                            })
                            .catch((error) => console.error(error))
                    }, 0)
                }
            }
        })
    },
    // ...
})

Credits

  • Think Studio