GithubHelp home page GithubHelp logo

Comments (5)

scrogson avatar scrogson commented on July 24, 2024

Hi @tsubery,

I'm hesitant to put this directly into this library. This library is meant to provide low-level OAuth2 building blocks.

Can you give me an example of how you are using this library so I can better understand what it is that you expect to accomplish?

Specifically, how are you storing tokens for later use?

from oauth2.

tsubery avatar tsubery commented on July 24, 2024

My use case is a long running background job that access google's api and collects information periodically. That means I need to store a token that eventually expires and need to be refreshed.

When I wrote the issue I forgot about the immutability of data in Elixir. I was thinking it would be clean and easy to make any request fetch for a new access token using the refresh token when necessary. This would work but the original client would not have the new access token and that might lead to many unnecessary round trips. I understand that this library does not implement a token store.

Having said that, there is still some minimal amount of logic can be abstracted away from users like me. All I really want is a token that is good for the next few minutes to do the required work. Maybe a function like this would be useful:

Updated:

def fresh_client_for(client, time_out_seconds) do
  expired_at = client.token.expired_at
   if expired_at && :os.system_time(:milli_seconds) + timeout_seconds < expired_at do
    refresh_token(client, [],[],[])
  else
    client
  end
end

Long running processes could use

fresh_client = fresh_client_for(stored_client, @max_access_time)
OAuth2.Client.get(fresh_client,...

from oauth2.

scrogson avatar scrogson commented on July 24, 2024

@tsubery,

Yeah, I've thought about including some sort of token store for a while. However, it seems difficult to make something generic enough to work with all use cases without further thought.

from oauth2.

tsubery avatar tsubery commented on July 24, 2024

Yea, seems like it might be mixing too many responsibilities. What do you think about the new function I suggested?

from oauth2.

scrogson avatar scrogson commented on July 24, 2024

@tsubery not at this time. Thank you.

from oauth2.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo 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.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.