{"id":15563211,"url":"https://github.com/timwaters/omniauth-mediawiki","last_synced_at":"2025-04-23T23:16:26.535Z","repository":{"id":19989685,"uuid":"23256922","full_name":"timwaters/omniauth-mediawiki","owner":"timwaters","description":"MediaWiki OAuth strategy for Omniauth, used for all wikimedia.org wikis (e.g. commons.wikimedia.org , wikipedia.org) with the oauth extension installed","archived":false,"fork":false,"pushed_at":"2021-08-09T18:32:08.000Z","size":41,"stargazers_count":4,"open_issues_count":4,"forks_count":9,"subscribers_count":4,"default_branch":"master","last_synced_at":"2025-04-23T23:16:20.476Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":null,"language":"Ruby","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"other","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/timwaters.png","metadata":{"files":{"readme":"README.md","changelog":"Changelog","contributing":null,"funding":null,"license":"LICENSE.md","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2014-08-23T13:51:27.000Z","updated_at":"2023-04-28T08:57:08.000Z","dependencies_parsed_at":"2022-07-22T03:32:01.289Z","dependency_job_id":null,"html_url":"https://github.com/timwaters/omniauth-mediawiki","commit_stats":null,"previous_names":[],"tags_count":11,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/timwaters%2Fomniauth-mediawiki","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/timwaters%2Fomniauth-mediawiki/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/timwaters%2Fomniauth-mediawiki/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/timwaters%2Fomniauth-mediawiki/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/timwaters","download_url":"https://codeload.github.com/timwaters/omniauth-mediawiki/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":250528902,"owners_count":21445519,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":[],"created_at":"2024-10-02T16:20:30.138Z","updated_at":"2025-04-23T23:16:26.490Z","avatar_url":"https://github.com/timwaters.png","language":"Ruby","funding_links":[],"categories":[],"sub_categories":[],"readme":"# OmniAuth Mediawiki\n\n\n[![Gem Version](https://badge.fury.io/rb/omniauth-mediawiki.svg)](https://badge.fury.io/rb/omniauth-mediawiki)\n\nThis gem contains the MediaWiki strategy for OmniAuth.\n\nMediaWiki uses the OAuth 1.0a extension, you can read about it here: https://www.mediawiki.org/wiki/Extension:OAuth\n\n## How To Use It\n\nUsage is as per any other OmniAuth 1.0 strategy. So let's say you're using Rails, you need to add the strategy to your `Gemfile` along side omniauth:\n\n    gem 'omniauth'\n    gem 'omniauth-mediawiki'\n\nOf course if one or both of these are unreleased, you may have to pull them in directly from github e.g.:\n\n    gem 'omniauth', :git =\u003e 'https://github.com/intridea/omniauth.git'\n    gem 'omniauth-mediawiki', :git =\u003e 'https://github.com/timwaters/omniauth-mediawiki.git'\n\nOnce these are in, you need to add the following to your `config/initializers/omniauth.rb`:\n\n    Rails.application.config.middleware.use OmniAuth::Builder do\n      provider :mediawiki, \"consumer_key\", \"consumer_secret\"\n    end\n\nIf you are using devise, this is how it looks like in your `config/initializers/devise.rb`:\n\n    config.omniauth :mediawiki, \"consumer_key\", \"consumer_secret\", \n                    {:client_options =\u003e {:site =\u003e 'https://commons.wikimedia.org' }}\n\nYou will obviously have to put in your key and secret, which you get when you register your app on your particula Wiki.\n\nNow just follow the README at: https://github.com/intridea/omniauth\n\n## Info about the MediaWiki OAuth extension\n\nIn general see the pages around https://www.mediawiki.org/wiki/OAuth/For_Developers for more information\n\nWhen registering for a new OAuth consumer registration you need to specify the callback url properly. e.g. for development:\n\n    http://localhost:3000/u/auth/mediawiki/callback \n    http://localhost:3000/users/auth/mediawiki/callback\n    \nInternally the strategy has to use  `/w/index.php?title=`  paths like so:\n\n    :authorize_path =\u003e '/wiki/Special:Oauth/authorize',\n    :access_token_path =\u003e '/w/index.php?title=Special:OAuth/token',\n    :request_token_path =\u003e '/w/index.php?title=Special:OAuth/initiate',\n    \nThis is a workaround as the paths should all be like the authorize path.\n\nNote also that new proposed registrations on mediawiki.org will work with your mediawki user that you registered the application with but have to be approved by an admin user for them to be useable by other users. \n\n## Specifying Target Wiki\n\nIf you would like to use this plugin against a wiki you should pass this you can use the environment variable WIKI_AUTH_SITE to set the server to connect to. Alternatively you can pass the site as a client_option to the omniauth config:\n\n    config.omniauth :mediawiki, \"consumer_key\", \"consumer_secret\",  \n                    :client_options =\u003e {:site =\u003e 'https://commons.wikimedia.org' }\n\nif no site is specified the www.mediawiki.org wiki will be used.\n\n## How to call the MediaWiki API via Omniauth\n\nWithin a Devise / Omniauth setup, in the callback method, you can directly get an OAuth::AccessToken  via ```request.env[\"omniauth.auth\"][\"extra\"][\"access_token\"]``` or you can get the token and secret from ```request.env[\"omniauth.auth\"][\"credentials\"][\"token\"]``` and ```request.env[\"omniauth.auth\"][\"credentials\"][\"secret\"]```\n\nAssuming these are stored in the user model, the following could be used to query the mediawiki API at a later date. In this example we are using the Wikimedia Commons API https://www.mediawiki.org/wiki/API:Main_page\n\n    @consumer = OAuth::Consumer.new \"consumer_key\",  \"consumer_secret\",  \n                        {:site=\u003e\"https://commons.wikimedia.org\"}\n    @access_token = OAuth::AccessToken.new(@consumer, user.auth_token, user.auth_secret) \n    uri = 'https://commons.wikimedia.org/w/api.php?action=query\u0026meta=userinfo\u0026uiprop=rights|editcount\u0026format=json'\n    resp = @access_token.get(URI.encode(uri))\n    logger.debug resp.body.inspect\n    # {\"query\":{\"userinfo\":{\"id\":12345,\"name\":\"WikiUser\",\n    # \"rights\":[\"read\",\"writeapi\",\"purge\",\"autoconfirmed\",\"editsemiprotected\",\"skipcaptcha\"],\n    # \"editcount\":2323}}}\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Ftimwaters%2Fomniauth-mediawiki","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Ftimwaters%2Fomniauth-mediawiki","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Ftimwaters%2Fomniauth-mediawiki/lists"}