diff --git a/lib/gitlab/oauth/user.rb b/lib/gitlab/oauth/user.rb
index 5efd5799f9feb4d175773605f9f15f98a002bbf5..1b04dffc3a853e689fa4dca89c8eee15a04621fc 100644
--- a/lib/gitlab/oauth/user.rb
+++ b/lib/gitlab/oauth/user.rb
@@ -86,6 +86,7 @@ module Gitlab
         end
 
         def username
+          return unless auth.info.respond_to?(:nickname)
           auth.info.nickname.to_s.force_encoding("utf-8")
         end
 
diff --git a/spec/lib/gitlab/oauth/user_spec.rb b/spec/lib/gitlab/oauth/user_spec.rb
index d6ac0c0896b62f9c1dde42c85b1fcdd46984245e..7dcc849454b88b7d9c50402cf65690e81ed2bfcc 100644
--- a/spec/lib/gitlab/oauth/user_spec.rb
+++ b/spec/lib/gitlab/oauth/user_spec.rb
@@ -68,5 +68,17 @@ describe Gitlab::OAuth::User do
       user = gl_auth.create(auth)
       expect(user.email).to_not be_empty
     end
+
+    it 'generates a username if non provided (google)' do
+      info = double(
+        uid: 'my-uid',
+        name: 'John',
+        email: 'john@example.com'
+      )
+      auth = double(info: info, provider: 'my-provider')
+
+      user = gl_auth.create(auth)
+      expect(user.username).to eql 'john'
+    end
   end
 end