Showing posts with label saml. Show all posts
Showing posts with label saml. Show all posts

Sunday, October 7, 2018

Python flask saml throwing saml2.sigver.SigverError Error Message

Leave a Comment

Has anyone succesfully implemented flask-saml using Windows as dev environment, Python 3.6 and Flask 1.0.2?

I was given the link to the SAML METADATA XML file by our organisation and had it configured on my flask app.

app.config.update({     'SECRET_KEY': 'changethiskeylaterthisisoursecretkey',     'SAML_METADATA_URL': 'https://<url>/FederationMetadata.xml', })  flask_saml.FlaskSAML(app) 

According to the documentation this extension will setup the following routes:

  • /saml/logout/: Log out from the application. This is where users go if they click on a “Logout” button.

  • /saml/sso/: Log in through SAML.

  • /saml/acs/: After /saml/sso/ has sent you to your IdP it sends you back to this path. Also your IdP might provide direct login without needing the /saml/sso/ route.

When I go to one of the routes http://localhost:5000/saml/sso/ I get the error below

saml2.sigver.SigverError saml2.sigver.SigverError: Cannot find ['xmlsec.exe', 'xmlsec1.exe']

I then went to this site https://github.com/mehcode/python-xmlsec/releases/tag/1.3.5 to get xmlsec and install it. However, I'm still getting the same issue.

Here is a screenshot of how I installed xmlsec

where does not seem to find the xmlsec.exe

enter image description here

1 Answers

Answers 1

documentationis asking to have xmlsec1 pre-installed. What you installed is a python binding to xmlsec1.

Get a windows build of xmlsec1 from here or build it from source And make it available in the PATH.

Read More

Saturday, August 4, 2018

single sign on (sso) laravel

Leave a Comment

I have three different laravel websites, I want to make user sign in at one website then he will be automatically logged in to the other two websites. eg. if you logged in at your stackoverflow then open stackexchange you will be logged in with StackOverflow account. I have tried many packages but they end with infinite exceptions or they simply not working. Most of the packages based on SAML, I have no idea why it did not work with me? I do not know what I miss? Is there any config for this to work? I am using laravel 5.6. All the apps are on the same server.

I have tried many solutions based on SAML, OpenID and share session, but all of them did not work with me. I do not know if I miss something. this is the last example I tried and it did not work

this is my code

SITE A

$site_b = 'http://s_sesstion_2.test/'; Route::get('/', function (Request $request) use ($site_b) {     $session_id = Session::getId();     try {         $http = new Client();         $response = $http->post($site_b . 'api/sessions/server', [             'form_params' => [                 'session_id' => $session_id,             ],             'headers' => [                 'Accept' => 'application/json',             ]         ]);     } catch (Exception $e) {         dd($e->getMessage());     }     return view('welcome'); }); 

SITE B (route/api.php)

    Route::post('/sessions/server', function (Request $request) {     Storage::disk('local')->put('file.txt', $request->get('session_id')); }); 

SITE B (route/web.php)

    Route::get('/', function () {     $session_id = Storage::disk('local')->get('file.txt');     Session::setId($session_id);     Session::start();     //return Session::getId();// will return the same session id     return \auth()->user();//this should return the auth user but it did not!! }); 

All I want is to sign in at site A then open site B I will be signed in. I will accept any solution achieve that purpose

2 Answers

Answers 1

I implemented an SSO solution without using SAML. I'll share my solution here, hope it helps.

Single Sign On

One application runs as the main authentication server at auth.domain. Other applications run in different domains app1.domain, app2.domain, ...

Every user is linked with SSO tokens. These tokens have very short expiration times. All authentication processes (signing in, resetting passwords, registering, ...) happen only in auth.domain application.

When a user visits any applications, for example, app-1.domain:

  1. Redirect user to auth.domain/login.
  2. If the user logged in our system before, continue at step 6.
  3. Show the sign in form, waiting for valid input.
  4. Generate a new SSO token with the expiration time less than 3 minutes.
  5. Attach the auth.domain remember me cookie to the response.
  6. Return a redirection response to the app-1.domain/sso/{sso_token}.
  7. app-1.domain application read the database. If the SSO token is valid and does not expire, find the user associated to that token.
  8. app-1.domain authenticates the user found in the previous step with Auth::login($user) method.
  9. app-1.domain clear the received SSO token from the database.

After this step, the user is authenticated to app-1.domain.

Session sharing

All shared session variables should be saved to databases. I implemented a new session driver:

  • Keep the list of shared session variable names
  • When reading/writing to sessions, check the name of the session variable. If that name is the previous list, read/write the value from the database. Otherwise, use the private session of each own application.

Answers 2

If your both applications share the same databases then you can follow the approach :

-> In your database , create a default session id that will be marked as false initially

-> Now as soon as user login to any of the site, generate a new hash and replace it with the default value.


optionally

-> You can also save the hash on browser local storage with hash as a key and null as value.


-> Now when user is logging into/switching to any of the site, check that hash -> If the hash matches the default, show the login page else show the profile page.


My answer is valid only if you are using common database for login else you need mapping for this.


Alternatively you can use cookies to store hash and can access them in cross domain. Can find example at Cross-Domain Cookies By @ludovic

Read More

Wednesday, October 11, 2017

Configuring GitLab to use SAML OmniAuth with an Active Directory IdP

Leave a Comment

I am in the process of altering an existing GitLab installation to use SAML rather than LDAP for authentication.

At this point, users can successfully sign into the Web application using the 'Sign in with Saml' button. I am unclear, however, about what seems to be a difference between the LDAP and SAML approaches: users with accounts created via an LDAP sign-in can then access Git repositories (e.g. using clone, push, ...) using their LDAP usernames and passwords, but users with accounts created via a SAML sign-in cannot.

Through experimentation, I’ve found that users can access the Git repositories if they use the GitLab UI to set a separate GitLab account password on the account that is created during the initial SAML interaction. I was pointed in this direction by a GitLab message that appeared after creating a project under one of the new user accounts: 'You won't be able to pull or push project code via HTTPS until you set a password on your account'.

It seems possible that this separate password configuration is only necessary because I’ve misconfigured the SAML integration somehow. So, my question is whether I am wrong to expect that authenticating access to the GitLab-hosted Git repositories would work the same regardless of whether SAML or LDAP is used? If not, does anyone know of relevant SAML configuration settings that I should review?

In case it’s of interest: I have posted a similar question to the GitLab Google group, but I have not received any responses there yet.

0 Answers

Read More

Thursday, May 25, 2017

desktop client application for SSO using SAML

Leave a Comment

I need to write a desktop based client application which does some web service method calls to a SharePoint server, after doing a SAML based SSO authentication.

I found that SAML SSO is mostly used from the browser which takes care of all the details. According to this question, it seems there is a technology in SAML 2.0 called ECP just for enabling non browser based clients.

Yet some applications like SharePoint 2010/2013 only support SAML 1.1; what can be used in this case?

1 Answers

Answers 1

You haven't mentioned technology - i can share my experience. We're required to have a SSO in the desktop application (WPF) that is using the WCF services. I have started with infomation from this link. The solution is to use WIF for retrieving the SAML token from identity provider and using it to establish the connection to our backend server.

  1. To obtain the token

    WSTrustChannelFactory GetTrustFactory() {     var binding = new WS2007HttpBinding(TrustChannelBindingConfiguration);     return new WSTrustChannelFactory(binding, StServiceUri); }  SecurityToken GetTokenFromSts() {     using (var trustFactory = GetTrustFactory())     {         // here is the code to set trustFactory.Credentials         trustFactory.TrustVersion = TrustVersion.WSTrust13;         var rst = new RequestSecurityToken                   {                       RequestType = RequestTypes.Issue,                       AppliesTo = new EndpointReference(YourServiceUri),                       KeyType = KeyTypes.Bearer                   };          var channel = (WSTrustChannel) trustFactory.CreateChannel();         try         {             return channel.Issue(rst);         }         catch (MessageSecurityException msex)         {             channel.Abort();             throw new EMException(msex.InnerException.Message, msex);         }     } } 
  2. Then the obtained token is used in service calls:

    securityToken = GetToken();      // 2. Create a channel with issued token to YourServiceInterface     // create binding and turn off sessions     var binding = new WS2007FederationHttpBinding(FederationBinding);      try     {         var factory = new ChannelFactory<YourServiceInterface>(binding,                           new EndpointAddress(YourServiceUri));          factory.Credentials.SupportInteractive = false;          var channel = factory.CreateChannelWithIssuedToken(securityToken);          // 3. Call YourMethod() on secured channel         return channel.YourMethod(); } catch {...} 

The main approach from the link hasn't been really changed - we just added token caching and incorporated this code in our channel handling framework. The code is used to authenticate desktop client against ADFS server and use claims in our backend server for authorizations.

Read More

Monday, April 18, 2016

WSO2IS NullPointerException when using step authenticator

Leave a Comment

Occasionally (?) the WSO2 IS user is unable to authenticate with following exception. When retrying, the user will be authenticated. Any ideas what could be reason / resolution? We set up the session caching.

Using WSO2 Identity Server 5.0.0.SP1 / SAML authentication with the authenticator set to advanced (single step, multiple options). I cannot find the correct source code commit to check out (to match the line number in the exception)

Thank you all in advance Gabriel

TID: [0] [IS] [2016-02-15 13:07:22,914] ERROR {org.wso2.carbon.identity.application.authentication.framework.handler.request.impl.DefaultRequestCoordinator} - Exception in Authentication Framework {org.wso2.carbon.identity.application.authentication.framework.handler.request.impl.DefaultRequestCoordinator} java.lang.NullPointerException at org.wso2.carbon.identity.application.authentication.framework.handler.sequence.impl.DefaultStepBasedSequenceHandler.handle(DefaultStepBasedSequenceHandler.java:83) at org.wso2.carbon.identity.application.authentication.framework.handler.request.impl.DefaultAuthenticationRequestHandler.handle(DefaultAuthenticationRequestHandler.java:121) at org.wso2.carbon.identity.application.authentication.framework.handler.request.impl.DefaultRequestCoordinator.handle(DefaultRequestCoordinator.java:94) at org.wso2.carbon.identity.application.authentication.framework.servlet.CommonAuthenticationServlet.doPost(CommonAuthenticationServlet.java:54) at org.wso2.carbon.identity.application.authentication.framework.servlet.CommonAuthenticationServlet.doGet(CommonAuthenticationServlet.java:44) at javax.servlet.http.HttpServlet.service(HttpServlet.java:735) at javax.servlet.http.HttpServlet.service(HttpServlet.java:848)

Edit:

This exception occurs on the WSO2 IS 5.1.0 too

see the Source code line 105

StepConfig stepConfig = context.getSequenceConfig().getStepMap().get(currentStep);  // if the current step is completed if (stepConfig.isCompleted()) {    stepConfig.setCompleted(false);  ERROR org.wso2.carbon.identity.application.authentication.framework.handler.request.impl.DefaultRequestCoordinator} -  Exception in Authentication Framework  java.lang.NullPointerException     at org.wso2.carbon.identity.application.authentication.framework.handler.sequence.impl.DefaultStepBasedSequenceHandler.handle(DefaultStepBasedSequenceHandler.java:105)     at org.wso2.carbon.identity.application.authentication.framework.handler.request.impl.DefaultAuthenticationRequestHandler.handle(DefaultAuthenticationRequestHandler.java:115) 

it looks like the stepConfig 'dissapeared' from the authentication config. The setup is done on a single node with session persistence into a database.

1 Answers

Answers 1

Apparently it looks like a problem with concurrency.

When multiple concurrent requests are sent to the SSO endpoint while the user is already authenticated, all threads are attempting to process the request modifying the same authentication context object (currentStep counter) so the cached authentication context comes to an invalid state.

Valid use case is that the client should send only a single request to the SSO endpoint, so the team dealing with the UI have to fix it. But - that's only the a quick fix not preventing the issue in long term. We have to really pick it up with WSO2 (and fix the code ourselves maybe) :)

g.

Read More