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

🚧 Initial version #1

Open
wants to merge 19 commits into
base: main
Choose a base branch
from
Open

🚧 Initial version #1

wants to merge 19 commits into from

Conversation

gr2m
Copy link
Contributor

@gr2m gr2m commented Mar 25, 2021

@ghost ghost added this to Inbox in JS Mar 25, 2021
@gr2m gr2m added the feature New feature or request label Mar 30, 2021
@ghost ghost moved this from Inbox to Features in JS Mar 30, 2021
@gr2m gr2m added the project Goes beyond a single bug fix or new feature. Help welcome by existing contributors. label Apr 22, 2021
@gr2m gr2m moved this from Features to Roadmap in JS Apr 22, 2021
@baoshan
Copy link

baoshan commented Jul 1, 2021

Any chance this initial version will be published and supported?
Looking forward to it!

@gr2m
Copy link
Contributor Author

gr2m commented Jul 1, 2021

I'm not working on it right now. I only ran the setup script npm init octokit-project and created a README:
https://github.com/octokit/auth-oauth-user-client.js/tree/initial-version#readme

If you'd like to work on it yourself let me know

@baoshan
Copy link

baoshan commented Jul 2, 2021

Aha! Thanks for the information! Is this client (and the authentication flow) compatible with your Cloudflare Worker?

@gr2m
Copy link
Contributor Author

gr2m commented Jul 2, 2021

It should be, if it's not I can help make it so. I'll have a look at https://github.com/gr2m/cloudflare-worker-github-oauth-login today to make sure it updated to the latest of everything. If you get stuck with anything please let me know :)

@gr2m
Copy link
Contributor Author

gr2m commented Jul 2, 2021

so actually https://github.com/gr2m/cloudflare-worker-github-oauth-login is not a good backend for it.

What you should use for the backend is @octokit/oauth-app (or @octokit/app, which includes @octokit/oauth-app). In particular, see the routes defined here: https://github.com/octokit/oauth-app.js#middlewares. These are the routes that will map perfectly to the features I'd like to see implemented in @octokit/auth-oauth-user-client

It should be straight forward to deploy an OAuth app using @octokit/oauth-app to Glitch. If you like I can do that and invite you to the glitch app? We could also add a local dev server for local testing to this repository?

@gr2m
Copy link
Contributor Author

gr2m commented Jul 2, 2021

@baoshan
Copy link

baoshan commented Jul 3, 2021

I’d like try Cloudflare Worker (the first time) for my next project.

I haven’t dive deep yet, but do you think it is possible to create a Cloudflare Worker which is compatible with @octokit/oauth-app (and also the to be implemented @octokit/auth-oauth-user-client.js as you envisioned)? If it is possible, I would like to contribute (both the worker and the client).

Thanks :)

@gr2m
Copy link
Contributor Author

gr2m commented Jul 4, 2021

Yes it’s absolutely possible. You can use the createNodeMiddleware() implementation (source) as a blueprint. I'd love a middleware for Cloudflare Workers, when you build it we can link it from the repository's README

@baoshan
Copy link

baoshan commented Jul 6, 2021

Can the (to be implemented) Cloudflare middleware benefit from @octokit/oauth-methods and hence @octokit/request? Are these low level @octokit/* modules Cloudflare compatible? Or is it better to add the create/check/reset/refresh/delete routes to cloudflare-worker-github-oauth-login.js as how it handles the token creation currently?

I guess some of the code in @octokit/oauth-app.js can be reused in the Cloudflare middleware oauth-app-cloudflare.js. For the client side, I also think @octokit/auth-oauth-user-client.js should share some code with @octokit/auth-oauth-user.js (types, etc.).

I believe cloudflare-worker-github-oauth-login.js does fit my needs for now although it is unable to be integrated with octokit.js in the browser. Oh my fault, it definitely can be used with octokit.js: just pass the token returned from the worker as a static one to octokit.js. May I ask: what is the benefit of auth-oauth-user-client.js + oauth-app-cloudflare.js over cloudflare-worker-github-oauth-login.js + octokit.js?

Thanks again for your patience.

@gr2m
Copy link
Contributor Author

gr2m commented Jul 6, 2021

Can the (to be implemented) Cloudflare middleware benefit from @octokit/oauth-methods and hence @octokit/request? Are these low level @octokit/* modules Cloudflare compatible?

Yes, they are! @octokit/request is depending on node-fetch, but for Cloudflare it should skip that dependency, as Cloudflare has the native fetch.

Or is it better to add the create/check/reset/refresh/delete routes to cloudflare-worker-github-oauth-login.js as how it handles the token creation currently?

I built https://github.com/gr2m/cloudflare-worker-github-oauth-login before @octokit/oauth-methods, otherwise I'd have used that

I guess some of the code in @octokit/oauth-app.js can be reused in the Cloudflare middleware oauth-app-cloudflare.js.

Yes, you should be able to use it. But I think Cloudflare workers work like serverless functions in that they don't keep state between requests? I'm not 100% sure about that. If they keep state, I'd use @octokit/auth-app. If they don't, I'd use the stateless @octokit/oauth-methods

For the client side, I also think @octokit/auth-oauth-user-client should share some code with @octokit/auth-oauth-user (types, etc.).

Both the code and the types of @octokit/auth-oauth-user.js is built on the assumption that clientSecret is set. That will not be the case for @octokit/auth-oauth-user-client. I'm sure their will be a lot of overlap, but for the sake of simplicity, I'd suggest to just copy & paste for now to make it work, and then we can look into how we can refactor it later, in order to remove code duplication?

what is the benefit of auth-oauth-user-client.js + oauth-app-cloudflare.js over cloudflare-worker-github-oauth-login.js + octokit.js?

My longer term goal is to server both a pre-configured @octokit/auth-oauth-user-client and a pre-authenticated/configured Octokit constructor from the OAuth server itself.

Right now, @octokit/oauth-app exposes all the {GET,POST,PATCH,DELETE} /api/github/* routes. Now imagine there would an cloudflare-octokit-app package that you'd only need to configure and deploy as Cloudflare worker, and it would not only expose the current {GET,POST,PATCH,DELETE} /api/github/* routes, but also GET /api/github/auth.js and GET /api/github/octokit.js.

GET /api/github/auth.js would give you a createOAuth function that you could just call without any configuration:

import { createOAuth } from "/api/github/auth.js"
const auth = createOAuth()

It would work just like the usage example but all configuration is preset for you, as it's tailored to your server instance.

And even simpler, you can load the Octokit constructor which is loading createOAuth and has authStrategy: createOAuth preset, so you can just do

import { Octokit } from "/api/github/auth.js"
const octokit = Octokit()

and it would just work™️

To circle back about the benefit: expiring OAuth tokens will become the norm in future. They are already enabled for new GitHub Apps by default. After 8h a token expires and is no longer valid. @octokit/auth-oauth-user-client can take of the renewal for you. It would automatically store both the authentication token and the reset token in browser storage (or just memory, depending on how you configure it for your app) and it would automatically renew a token if the server responds with a 401 token expired error.

@baoshan
Copy link

baoshan commented Aug 9, 2021

Thanks for the suggestions! I’m ready to help when you’ve reviewed the PR.

@gr2m
Copy link
Contributor Author

gr2m commented Aug 17, 2021

@baoshan hey just checking in to make sure you are not blocked by something? Anything I can help with?

@gr2m gr2m removed their assignment Aug 17, 2021
@ghost ghost moved this from In progress to Features in JS Aug 17, 2021
@gr2m gr2m added the awaiting response Clarification needed by author label Aug 17, 2021
@ghost ghost moved this from Features to Awaiting response in JS Aug 17, 2021
@baoshan
Copy link

baoshan commented Aug 17, 2021

Are you expecting me to fix the conditional chaining issue?

Is it fine to use jest for now? Is there anything else that doesn’t look good? I thought there may be other issues in the commit to discuss so I didn’t fix that (conditional chaining) issue in time.

Sorry for the delay anyway, I’ll submit a PR later.

@gr2m
Copy link
Contributor Author

gr2m commented Aug 17, 2021

Are you expecting me to fix the conditional chaining issue?

no need, as it's a new package and we don't need to support Node 10.

Is it fine to use jest for now? Is there anything else that doesn’t look good? I thought there may be other issues in the commit to discuss so I didn’t fix that (conditional chaining) issue in time.

Yes Jest is fine

Sorry for the delay anyway, I’ll submit a PR later.

No worries at all, no rush.

I just realized I meant to do a thorough review of this PR, I'll do that tomorrow

@gr2m gr2m removed the awaiting response Clarification needed by author label Aug 17, 2021
@ghost ghost moved this from Awaiting response to Features in JS Aug 17, 2021
@gr2m gr2m self-assigned this Aug 17, 2021
@ghost ghost moved this from Features to In progress in JS Aug 17, 2021
@ArtemMelnychenko
Copy link

@gr2m Hello. Do you need any help on this? I have managed to fix test errors on my fork (by removing ?. and ?? and syntax), and also there was a bug in the path to token (this.session was set to response.data instead of {authentication: response.data}).

I have tested it locally with the POC project I was working on, it works :)

@gr2m
Copy link
Contributor Author

gr2m commented Sep 19, 2021

@ArtemMelnychenko Any help is much appreciated! Can you send a PR against the initial-version branch?

I'm focused on https://github.com/octokit/octokit-next.js right now and for the coming weeks and months, but I'd love to get @octokit/auth-oauth-user-client released

@baoshan
Copy link

baoshan commented Sep 20, 2021

there was a bug in the path to token (this.session was set to response.data instead of {authentication: response.data}).

Hi @ArtemMelnychenko! Thanks for testing the draft!

I’m not sure why you need to set this.session to {authentication: response.data}. oauth-app.js middleware responds with {authentication: {...}} already (see test).

Could you let me know why the current implementation fails on your POC project? Thanks.

@baoshan
Copy link

baoshan commented Sep 20, 2021

Personally I hope the nullish coalescing operator (??) and optional chaining (?.) are fine for the source code. They’re supported by major browsers for more than 18 months. If we need to cover older browsers, we can change tsconfig.json to output es2019 code.

@Plazmius
Copy link

Plazmius commented Sep 20, 2021

@baoshan thanks for the clarification. Indeed, it's covered by a test and there was a link to the oauth-app.js default handler for this in the initial-version branch readme . I think I have skipped through because I was looking at the main branch readme and didn't find the link. So I have implemented the handler myself, sorry for the misleading commit.

regarding coalescing operator (??) and optional chaining (?.) - I have tested inside docker node:12 image and can confirm that setting the target to es2019 allows jest tests to succeed. However, pika build throws a warning
tsconfig.json [compilerOptions.target] should be "ES2020", but found "ES2019". You may encounter problems building.
and compiles to ES2020 anyway.`

Should I proceed with reverting the previous commits and add es2019 target in my pull request?

Edit: alternatively, we could override target in the global jest config as described here. I have tested it too, then we can avoid the warning.

@baoshan
Copy link

baoshan commented Sep 20, 2021

Thanks very much @Plazmius for letting me know the details.

I’m fine with removing node 12 from the matrix. I guess esbuild is more suitable for front-end bundling if old browsers should be supported since @pika/plugin-standard-pkg always compiles to es2020.

I think @gr2m is too busy to review the code. If that is the case, could you kindly help him by giving initial-version branch a review? If everything looks good, could @gr2m publish a release? I will keep watching the project for issues reported.

BTW, will this be compatible with octokit-next?

@Plazmius
Copy link

Plazmius commented Sep 21, 2021

@baoshan I will submit the review with pleasure. Should I create a PR for removing test matrix for node 12 first, or go ahead with the review? Is there any guidelines/requirements for submitting the review, because I didn't find any? Thanks

@gr2m
Copy link
Contributor Author

gr2m commented Sep 21, 2021

I’m fine with removing node 12 from the matrix. I guess esbuild is more suitable for front-end bundling if old browsers should be supported since @pika/plugin-standard-pkg always compiles to es2020.

I'm okay with that, too. I'd rather unblock us here and change things later :)

I think @gr2m is too busy to review the code.

Sorry for the delay, I'm trying to catch up soon

BTW, will this be compatible with octokit-next?

Don't worry about that right now, I'll do once we get there. I cannot think of a reason why it shouldn't

@wolfy1339 wolfy1339 mentioned this pull request Jun 13, 2022
@baoshan
Copy link

baoshan commented Jun 15, 2022

There’re several known issues in my draft implementation (the initial-version branch of this repo currently). I’m willing to submit a PR if maintainers decided to move on. Just let me know.

For anybody who needs this strategy now, you can use my fork.

@gr2m
Copy link
Contributor Author

gr2m commented May 22, 2023

@baoshan hey I'm interested in moving this forward :) What's the latest status with your port? We are in the process of removing the pika build tools and replacing them with esbuild and tsc (see for example octokit/app.js#420).

I'd also be interested in figuring out how to build a React Provider for Octokit using this plugin. Do you know if there is any prior art in that direction?

@baoshan
Copy link

baoshan commented May 22, 2023

It has no known issue but I may be the only user.

  • I use a single-file layout.
  • I use deno bundle mod.ts index.bundle.js to bundle for the browser.

I do not currently have time to rewrite the tests in Jest (which is heavy IMHO) or make an esbuild script.

PS: I know little about React.

@gr2m
Copy link
Contributor Author

gr2m commented May 22, 2023

Sounds good, I'll see if I can find the time this weekend to merge your changes and adapt them to the @octokit conventions

Jest (which is heavy IMHO)

yeah I replaced Jest with ava in https://github.com/octokit/octokit-next.js for that reason.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
feature New feature or request project Goes beyond a single bug fix or new feature. Help welcome by existing contributors.
Projects
No open projects
JS
  
In progress
Development

Successfully merging this pull request may close these issues.

None yet

5 participants