Skip to content

Adding OKTA Single Sign-on Support - #568

Closed
forescout-spollock wants to merge 2 commits into
BookStackApp:masterfrom
forescout-spollock:master
Closed

forescout-spollock wants to merge 2 commits into
BookStackApp:masterfrom
forescout-spollock:master

Conversation

@forescout-spollock

Copy link
Copy Markdown
  1. In the .env file add

OKTA_URL=https://dev-454412.oktapreview.com/
OKTA_REDIRECT=http://servername/login/service/okta/callback
OKTA_CLIENT_ID=fsxxxxxxxdfg
OKTA_CLIENT_SECRET= fsdxxxxx-xxxxx-xxxxxx3

Replacing the OKTA_URL,OKTA_REDIRECT,OKTA_CLIENT_ID,OKTA_CLIENT_SECRET with your respective values.

You can sign up for a development account at developer.okta.com - the application type should be web, redirect URI: wiki.com/login/service/okta/callback

Manual installation steps are:

Add the file okta.svg to BookStack/resources/assets/icons

3.Add the file
BookStack/vendor/laravel/socialite/src/Two/OktaProvider.php

In BookStack/config/services.php
add

'okta' => [
'url' => env('OKTA_URL'),
'client_id' => env('OKTA_CLIENT_ID'),
'client_secret' => env('OKTA_CLIENT_SECRET'),
'redirect' => env('OKTA_REDIRECT'),
'name'          => 'Okta',
]

In BookStack/app/Services/SocialAuthService.php add to the variable $validSocialDrivers okta
i.e
protected $validSocialDrivers = ['google', 'github', 'facebook', 'slack', 'twitter', 'azure','okta'];

In BookStack/vendor/laravel/socialite/src/SocialiteManager.php add

public function createOktaDriver() {
$config = $this->app ['config'] ['services.okta'];

	$provider = $this->buildProvider ( 'Laravel\Socialite\Two\OktaProvider', $config );
	
	$provider->setOktaUrl ( $config ['url'] );
	
	return $provider;
}

In BookStack/config/setting-defaults.php change registration-enabled to true
i.e 'registration-enabled' => true,

@forescout-spollock

Copy link
Copy Markdown
Author

There are some changes with sign-up and auto-login that we have not solved and could use your help.

@lommes

lommes commented Oct 26, 2017

Copy link
Copy Markdown
Member

You should never manually modify files in the vendor folder. All files in there come through composer and are maintained by their creator. These changes will get lost with every update of the dependecies. The vendor-folder is excluded from the repo since it can be recreated identically on every system thanks to composer. To use okta with bookstack there should be used a package that extends socialite like e.g. https://github.com/tequilarapido/socialite-okta (just googled, i have no experience with this package)

@s0n-

s0n- commented Nov 5, 2017

Copy link
Copy Markdown

@ssddanbrown - Any info on this - I know we would love this merged into the main code branch.

@ssddanbrown

Copy link
Copy Markdown
Member

@forescout-spollock Thanks for creating this pull request.

As @lommes has mentioned, The content in /vendor should not be altered directly and, at least for BookStack, should not be committed into git. Due to the vendor folder being added it makes looking through this very difficult.

Please could you open a new pull request without the /vendor folder committed so the changes are clear? If you need help moving custom code from /vendor just let me know.

@jacksonp2008

Copy link
Copy Markdown

Archive.zip
Gents, this is the only way we were able to get it to work is by modifying in /vendor. There is really very little to it, so let me post more comprehensive instructions and files directly here. If you need more let me know, happy to help. We just needed to move this forward, not proud of the code.

Modify .env

In the .env file, located in the root of the application, generally /var/www/boostack

Add the following stanza:

# OKTA Settings
OKTA_URL=https://fsu.okta.com/
OKTA_REDIRECT=http://bookstack.fsu.com/login/service/okta/callback
OKTA_CLIENT_ID=0oasdfsafsfsdfsf7
OKTA_CLIENT_SECRET=YH6asdfsadfsadfsadfsadf5

Add the OKTA Icon

Add the file okta.svg to {bookstack root}/resources/assets/icons

Add the Okta Provider file

Add the file OktaProvider.php to {bookstack root}/vendor/laravel/socialite/src/Two/

Edit the Services.php file

In {bookstack root}/config/services.php add the following:


    'okta' => [
    'url' => env('OKTA_URL'),
    'client_id' => env('OKTA_CLIENT_ID'),
    'client_secret' => env('OKTA_CLIENT_SECRET'),
    'redirect' => env('OKTA_REDIRECT'),
        'name'          => 'Okta',
    ],

Edit the SocialAuthServices file

In {bookstack root}/app/Services/SocialAuthService.php add to the variable $validSocialDrivers okta

protected $validSocialDrivers = ['google', 'github', 'facebook', 'slack', 'twitter', 'azure','okta'];

Edit the SocialiteManager file

In {bookstack root}/vendor/laravel/socialite/src/SocialiteManager.php add thefollowing:

    /** 
     * Build an OKTA provider instance


     *  
     */

    public function createOktaDriver()
    {
        $config = $this->app ['config'] ['services.okta'];
        $provider = $this->buildProvider ( 'Laravel\Socialite\Two\OktaProvider', $config );
        $provider->setOktaUrl ( $config ['url'] );

        return $provider;
    }

###Enable Registration through OKTA
In {bookstack root}/config/setting-defaults.php change registration-enabled to true

<?php

/**
 * The defaults for the system settings that are saved in the database.
 */
return [

    'app-name'        => 'BookStack',
    'app-logo' => '',
    'app-name-header' => true,
    'app-editor'      => 'wysiwyg',
    'app-color'       => '#0288D1',
    'app-color-light' => 'rgba(21, 101, 192, 0.15)',
    'app-custom-head' => false,
    'registration-enabled' => true,

];

@lommes

lommes commented Nov 7, 2017

Copy link
Copy Markdown
Member

Bookstack does not ship with a vendor folder. All these files are downloaded when composer install is run on the target system. Adding the vendor folder will bypass some basic features of composer (scanning for needed PHP extensions and versions). When adding files manually these changes have to be (manually) merged again on each update which is way less userfriendly than simply running composer install.

Since adding an additional socialite provider for okta seems to be a recurring request and the more providers BookStack supports the better, I will give this a shot and create pullrequest if it is achievebale in a proper way.

@lommes

lommes commented Nov 13, 2017

Copy link
Copy Markdown
Member

I now have a working version without adding vendor. Since there are no packages which are actively maintained and the one i mentioned before is built for laravel 5.1 and socialite 2 there are still several problems.

I tend to create an own provider from scratch for laravel 5.4+. Since it most likely would be exclusivly for bookstack and there now is a ticket to update bookstack to laravel 5.5, does it make sense to add a 5.4 compatible package now or wait for that update? It would be easier to fork the existing package and override it in composer.json using a custom repository which, in my opinion, is not a good practice for an app in production.

@ssddanbrown what's your opinion on this?

@ssddanbrown

Copy link
Copy Markdown
Member

@lommes If you're creating a provider from scratch it's up to you how you like to integrate it really. I'll be upgrading master branch to 5.5 today if you were waiting for that (To start work on v0.19).

You can either have the provider in your own repo, Which we can bring in via composer or, if it's easier for you and you don't mind, You can just place the files in the services and/or provider folders within app if that's possible.

Thanks for your efforts so far on this.

@lommes

lommes commented Nov 26, 2017

Copy link
Copy Markdown
Member

I just added #598 so I think this can be closed.

@ssddanbrown

Copy link
Copy Markdown
Member

Closing this now due to #598 being merged in.

@ssddanbrown ssddanbrown closed this Dec 9, 2017
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Development

Successfully merging this pull request may close these issues.

5 participants