Function getToken

  • Use this function to retrieve tokens by using a username and password.

    If you are using this function in a browser environment, you need to specify the origin. If you try to access a Wikimedia server, you need to be on a Wikimedia domain. All other domains are blocked. See https://phabricator.wikimedia.org/T22814 and https://noc.wikimedia.org/conf/highlight.php?file=CommonSettings.php#:~:text=%24wgCrossSiteAJAXdomains

    You can pass in a custom axios instance to use for the requests. This is mainly intended for CORS circumvention purposes. Use, for example, axios-over-http to do the actual requests on a server. The only requirement for these axios instances is that they have the same API as the axios package. The only required function is the main axios() function.

    Parameters

    • username: string

      The username of the user

    • password: string

      The password of the user

    • Optionalconfig: GetTokenConfig

      The config for the function

      • server

        The server to get the token from

      • origin

        The origin to use for the API calls, aka the "domain" of the web app (only needed for CORS)

      • axiosOptions

        The options to pass to axios. Please use sparingly as this may be considered a hack. Please open an issue if you need this.

      • axiosInstance

        The axios instance to use. This is mainly intended for CORS circumvention purposes. Use, for example, axios-over-http to do the actual requests on a server.

    Returns Promise<Token>

    An object containing the token and the cookie

    If the login was not successful

    const token = await getToken('your wikidata username', 'your wikidata password');
    upload(item, {
    summary: 'test update',
    authToken: token
    });