]> git.openstreetmap.org Git - rails.git/blobdiff - app/models/user.rb
Merge remote-tracking branch 'upstream/pull/3237'
[rails.git] / app / models / user.rb
index 964359e9cd4cec972f596f08eec1b45c71de3fe2..c02795a4af9656f4e8219d15dd942ab54e27a26c 100644 (file)
@@ -288,11 +288,23 @@ class User < ApplicationRecord
   end
 
   ##
-  # return an oauth access token for a specified application
+  # return an oauth access token for a specified application
   def access_token(application_key)
     ClientApplication.find_by(:key => application_key).access_token_for_user(self)
   end
 
+  ##
+  # return an oauth 2 access token for a specified application
+  def oauth_token(application_id)
+    application = Doorkeeper.config.application_model.find_by(:uid => application_id)
+
+    Doorkeeper.config.access_token_model.find_or_create_for(
+      :application => application,
+      :resource_owner => self,
+      :scopes => application.scopes
+    )
+  end
+
   def fingerprint
     digest = Digest::SHA256.new
     digest.update(email)