Comments (7)
💡
In order for that to be possible, we have to add a new
Octokit
strategy option, and@octokit/core
will have to set it tothis.constructor
in https://github.com/octokit/core.js/blob/c44da9b6a3ea3edc7882c9f776639215a6f53bca/src/index.ts#L138-L145
instead of an Octokit
strategy option that would be called internally with new Octokit({ auth: { [strategy options here] } })
, I figured it makes more sence to call the option installationAuth
which will be called with just { [strategy options here] }
.
That will remove the interdependence between the two packages entirely.
@octokit/core
can set this option to
const auth = options.authStrategy(
Object.assign(
{
request: this.request,
installationAuth: auth => new this.constructor(auth)
},
options.auth
)
);
And @octokit/auth-app
can default to option to installationAuth: auth => createAppAuth(auth)
, so this would work out-of-the-box:
const appAuth = createAppAuth({
id: 1,
privateKey: "-----BEGIN PRIVATE KEY-----\n..."
});
const installationAuth123 = await appAuth({ type: "installation-auth", installationId: 123 })
const installationAuth456 = await appAuth({ type: "installation-auth", installationId: 456 })
And all three *Auth
instances would share the same state, including installation access code.
from auth-app.js.
💡💡
Maybe even simpler, instead of introducing an entirely new type "installation-auth"
or "installation-octokit"
, we could introduce a new option to the existing "installation"
and maybe also the "oauth"
type which would be a function that gets called with all the strategy options plus the installationId
set in the auth()
call. Something like this:
const appAuth = createAppAuth({
id: 1,
privateKey: "-----BEGIN PRIVATE KEY-----\n...",
});
const installationAuth123 = await appAuth({
type: "installation",
installationId: 123,
factory: createAppAuth,
});
For @octokit/core
, no changes would need to be done. But when I have an octokit instance with app authentication and I want an instance with installation authentication, it'd look like this
const appOctokit = new Octokit({
authStrategy: createAppAuth,
auth: { id, privateKey },
});
const installationOctokit = await appOctokit.auth({
type: "installation",
installationId,
factory: (auth) => new appOctokit.constructor({ auth }),
});
I think I like that approach the best!
from auth-app.js.
🎉 This issue has been resolved in version 2.8.0 🎉
The release is available on:
Your semantic-release bot 📦🚀
from auth-app.js.
Hi. These usage examples don't seem to work verbatim anymore (including the one in the documentation). What's the latest recommendation? I've found a few alternatives, but I want to make sure to take advantage of the reused cache as mentioned in the docs.
from auth-app.js.
@gr2m Sorry for the ping. I just wanted to see if the documentation on this might need an update.
from auth-app.js.
Sorry but I cannot help right now, GitHub did not extend my contract:
octokit/octokit.js#620 (comment)
Here is how @octokit/core
passes itself to the configured authentication strategy, hope that helps:
https://github.com/octokit/core.js/blob/master/src/index.ts#L121-L160
from auth-app.js.
@gr2m I see, I'm very sorry to hear that. Thanks for all of your hard work.
It seems like we just need to make sure that the factory function returns a new Octokit specifying both auth and authStrategy for the case of app installation auth. Some of the more implicit attempts threw exceptions that I was not using a string (token?) as auth.
from auth-app.js.
Related Issues (20)
- [BUG]: ReferenceError: Property 'atob' doesn't exist HOT 9
- [BUG]: secretOrPrivateKey must be an asymmetric key when using RS256 HOT 29
- [BUG]: package files not published to npm HOT 1
- [BUG]: unable to use this package with `@actions/github-script` HOT 19
- [DOCS]: Node version requirements HOT 3
- Replace `toMatchObject` Response assertions with `toEqual` in `auth-app.js` HOT 1
- [DOCS]: Implementation of GitHub App user authentication token with expiring disabled HOT 6
- [BUG]: Cache#get type doesn't allow promises HOT 2
- [BUG]: Upgrade universal-github-app-jwt 1.1.2 to close CVE-2022-25883 HOT 5
- Default flow results in error for missing installationId HOT 5
- [BUG]: `octokit.request("PATCH /app/hook/config", { url })` throws error `installationId option is required for installation authentication` HOT 1
- [BUG]: Handle 403 responses same as 401 responses in the first 3 seconds after an installation access token was created HOT 1
- [BUG]: /app/installation-requests missing from PATHS in requires-app-auth HOT 3
- Revisit skipped tests HOT 1
- `appId` can now be set to the application's Client ID HOT 2
- [MAINT]: use stable `semantic-release` HOT 2
- [BUG]: require("@octokit/auth-app"); Error [ERR_REQUIRE_ESM]: require() of ES Module HOT 6
- [BUG]: Update 6.1.0 -> 6.1.1 results in runtime error in AWS HOT 6
- Document that clientId may be assigned to the appId property HOT 1
- [BUG]: when setting `baseUrl` as part of parameters, the `baseUrl` is not passed through to `getInstallationAuthentication` HOT 2
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from auth-app.js.