summaryrefslogtreecommitdiff
path: root/lib/gitlab/auth/atlassian/user.rb
diff options
context:
space:
mode:
Diffstat (limited to 'lib/gitlab/auth/atlassian/user.rb')
-rw-r--r--lib/gitlab/auth/atlassian/user.rb35
1 files changed, 35 insertions, 0 deletions
diff --git a/lib/gitlab/auth/atlassian/user.rb b/lib/gitlab/auth/atlassian/user.rb
new file mode 100644
index 00000000000..6ab7741cc54
--- /dev/null
+++ b/lib/gitlab/auth/atlassian/user.rb
@@ -0,0 +1,35 @@
+# frozen_string_literal: true
+
+module Gitlab
+ module Auth
+ module Atlassian
+ class User < Gitlab::Auth::OAuth::User
+ def self.assign_identity_from_auth_hash!(identity, auth_hash)
+ identity.extern_uid = auth_hash.uid
+ identity.token = auth_hash.token
+ identity.refresh_token = auth_hash.refresh_token
+ identity.expires_at = Time.at(auth_hash.expires_at).utc.to_datetime if auth_hash.expires?
+
+ identity
+ end
+
+ protected
+
+ def find_by_uid_and_provider
+ ::Atlassian::Identity.find_by_extern_uid(auth_hash.uid)&.user
+ end
+
+ def add_or_update_user_identities
+ return unless gl_user
+
+ identity = gl_user.atlassian_identity || gl_user.build_atlassian_identity
+ self.class.assign_identity_from_auth_hash!(identity, auth_hash)
+ end
+
+ def auth_hash=(auth_hash)
+ @auth_hash = ::Gitlab::Auth::Atlassian::AuthHash.new(auth_hash)
+ end
+ end
+ end
+ end
+end