Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Any plans for Gitea support? #589

Open
zeerd opened this issue Aug 12, 2022 · 1 comment
Open

Any plans for Gitea support? #589

zeerd opened this issue Aug 12, 2022 · 1 comment

Comments

@zeerd
Copy link

zeerd commented Aug 12, 2022

Hope so.

@zeerd
Copy link
Author

zeerd commented Aug 16, 2022

I did some try.

  1. cp oauth/vendor/lusitanian/oauth/src/OAuth/OAuth2/Service/GitHub.php to oauth/vendor/lusitanian/oauth/src/OAuth/OAuth2/Service/Gitea.php

modify Gitea.php like:

--- oauth/vendor/lusitanian/oauth/src/OAuth/OAuth2/Service/GitHub.php   2022-05-04 05:38:50.000000000 +0800
+++ oauth/vendor/lusitanian/oauth/src/OAuth/OAuth2/Service/Gitea.php    2022-08-15 16:14:14.177387810 +0800
@@ -10,7 +10,7 @@
 use OAuth\Common\Storage\TokenStorageInterface;
 use OAuth\OAuth2\Token\StdOAuth2Token;
 
-class GitHub extends AbstractService
+class Gitea extends AbstractService
 {
     /**
      * Defined scopes, see http://developer.github.com/v3/oauth/ for definitions.
@@ -124,6 +124,8 @@
      */
     const SCOPE_PUBLIC_KEY_ADMIN = 'admin:public_key';
 
+    const GITEA_HOST_DEFAULT = 'http://x.x.x.x';
+
     public function __construct(
         CredentialsInterface $credentials,
         ClientInterface $httpClient,
@@ -134,7 +136,7 @@
         parent::__construct($credentials, $httpClient, $storage, $scopes, $baseApiUri);
 
         if (null === $baseApiUri) {
-            $this->baseApiUri = new Uri('https://api.github.com/');
+            $this->baseApiUri = new Uri(static::GITEA_HOST_DEFAULT . '/api/v1/');
         }
     }
 
@@ -143,7 +145,7 @@
      */
     public function getAuthorizationEndpoint()
     {
-        return new Uri('https://github.com/login/oauth/authorize');
+        return new Uri(static::GITEA_HOST_DEFAULT . '/login/oauth/authorize');
     }
 
     /**
@@ -151,7 +153,7 @@
      */
     public function getAccessTokenEndpoint()
     {
-        return new Uri('https://github.com/login/oauth/access_token');
+        return new Uri(static::GITEA_HOST_DEFAULT . '/login/oauth/access_token');
     }
 
     /**
  1. install oauthgithub, rename it to oauthgitea
diff -r -u oauthgithub/action.php oauthgitea/action.php
--- oauthgithub/action.php      2021-12-15 14:51:44.000000000 +0800
+++ oauthgitea/action.php       2022-08-15 16:27:27.457387715 +0800
@@ -1,11 +1,11 @@
 <?php
 
-use OAuth\OAuth2\Service\GitHub;
+use OAuth\OAuth2\Service\Gitea;
 
 /**
  * Service Implementation for oAuth Github authentication
  */
-class action_plugin_oauthgithub extends \dokuwiki\plugin\oauth\Adapter
+class action_plugin_oauthgitea extends \dokuwiki\plugin\oauth\Adapter
 {
 
     /** * @inheritDoc */
@@ -34,13 +34,13 @@
     /** @inheritDoc */
     public function getScopes()
     {
-        return [GitHub::SCOPE_USER_EMAIL];
+        return [Gitea::SCOPE_USER_EMAIL];
     }
 
     /** @inheritDoc */
     public function getLabel()
     {
-        return 'GitHub';
+        return 'Gitea';
     }
 
     /** @inheritDoc */
diff -r -u oauthgithub/plugin.info.txt oauthgitea/plugin.info.txt
--- oauthgithub/plugin.info.txt 2021-12-15 14:51:44.000000000 +0800
+++ oauthgitea/plugin.info.txt  2022-08-15 14:29:23.693388561 +0800
@@ -1,1 +1,1 @@
-base   oauthgithub
+base   oauthgitea

It works!

But, I do not know the means of those const variables like SCOPE_USER. So I am not sure if this safe enough.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant