pow-auth / assent

Multi-provider framework in Elixir
https://powauth.com
MIT License
391 stars 45 forks source link

Add refresh token logic #53

Closed danschultzer closed 3 years ago

danschultzer commented 3 years ago

Was prompted by this question on elixir slack by mohamedAqib:

is there anyway for me to get an automated job to refresh the token of users based on their provider it connects to if i use pow_assent? I understand that part (auth with own system). What i meant was how to automate the access token from provider. Eg if the user sign in with Microsoft graph, the token access only for 1 hour. Is there any built in pow method to get a new access token from Microsoft graph (using the given refresh token)

I realized that there isn't really an easy way to do this with Assent or PowAssent, so this adds a Assent.Strategy.OAuth2.refresh_access_token/3 method that can be called to update the access token.

Examples:

Assent.Strategy.OAuth2.refresh_access_token(strategy_config, %{"refresh_token" => refresh_token})

Assent.Strategy.OAuth2.refresh_access_token(strategy_config, %{"refresh_token" => refresh_token}, scope: "read")