Browse Source

Merge branch 'devel' of https://github.com/salleman33/wekan into salleman33-devel

Lauri Ojansivu 6 years ago
parent
commit
96173ad431
3 changed files with 47 additions and 0 deletions
  1. 1 0
      .meteor/packages
  2. 27 0
      models/users.js
  3. 19 0
      server/authentication.js

+ 1 - 0
.meteor/packages

@@ -31,6 +31,7 @@ kenton:accounts-sandstorm
 service-configuration@1.0.11
 service-configuration@1.0.11
 useraccounts:unstyled
 useraccounts:unstyled
 useraccounts:flow-routing
 useraccounts:flow-routing
+salleman:accounts-oidc
 
 
 # Utilities
 # Utilities
 check@1.2.5
 check@1.2.5

+ 27 - 0
models/users.js

@@ -478,6 +478,33 @@ if (Meteor.isServer) {
       return user;
       return user;
     }
     }
 
 
+    if (user.services.oidc) {
+      var email = user.services.oidc.email.toLowerCase();
+      
+      user.username = user.services.oidc.username;
+      user.emails = [{ address: email,
+		       verified: true }];
+      var initials = user.services.oidc.fullname.match(/\b[a-zA-Z]/g).join('').toUpperCase();
+      user.profile = { initials: initials, fullname: user.services.oidc.fullname };
+
+      // see if any existing user has this email address or username, otherwise create new
+      var existingUser = Meteor.users.findOne({$or: [{'emails.address': email}, {'username':user.username}]});
+	    console.log("user to create : ");
+	    console.log(user);
+      if (!existingUser)
+        return user;
+
+      // copy across new service info
+      var service = _.keys(user.services)[0];
+      existingUser.services[service] = user.services[service];
+      existingUser.emails = user.emails;
+      existingUser.username = user.username;
+      existingUser.profile = user.profile;
+
+      Meteor.users.remove({_id: existingUser._id}); // remove existing record
+      return existingUser;
+    }
+
     if (options.from === 'admin') {
     if (options.from === 'admin') {
       user.createdThroughApi = true;
       user.createdThroughApi = true;
       return user;
       return user;

+ 19 - 0
server/authentication.js

@@ -62,5 +62,24 @@ Meteor.startup(() => {
     Authentication.checkAdminOrCondition(userId, normalAccess);
     Authentication.checkAdminOrCondition(userId, normalAccess);
   };
   };
 
 
+  if (Meteor.isServer) {
+    ServiceConfiguration.configurations.upsert(
+      { service: 'oidc' },
+      {
+        $set: {
+          loginStyle: 'redirect',
+          clientId: 'CLIENT_ID',
+          secret: 'SECRET',
+          serverUrl: 'https://my-server',
+          authorizationEndpoint: '/oauth/authorize',
+          userinfoEndpoint: '/oauth/userinfo',
+          tokenEndpoint: '/oauth/token',
+          idTokenWhitelistFields: [],
+          requestPermissions: ['openid']
+        }
+      }
+    );
+    }
+
 });
 });