def test_generate_accept(self): from oath.google_authenticator import from_b32key secret = 'GG' gauth = from_b32key(secret) self.assertTrue(gauth.accept(gauth.generate())) self.assertFalse(gauth.accept('111111'))
def authenticate(self, configAttributes, requestParams, step): userService = UserService.instance() authService = AuthenticationService.instance() username = requestParams.get('username')[0] token = requestParams.get('token')[0] if not username or not token: print 'Empty input data: username=%s token=%s' % (username, token) return False # Check if the is user with specified oneid_user_uid user_found = userService.getUserByAttribute("username", username) if not user_found: print "The username %s was not found on the system." % username return False credentials = Identity.instance().getCredentials() credentials.setUsername(username) credentials.setUser(user_found) secret = base64.b32encode(credentials.getPassword()) token_generated = from_b32key(secret).generate(t=time.time()) if int(token) == int(token_generated): authService.authenticate(username) print "OATH Authentication Successful for %s" % username return True
def test_simple(self): from oath.google_authenticator import from_b32key l = ( # generated from http://gauth.apps.gbraad.nl/ (1391203240, 'GG', '762819'), (1391203342, 'FF', '737839'), ) for t, b32_key, result in l: self.assertEquals(from_b32key(b32_key).generate(t=t), result)