okta / okta-oidc-xamarin

Okta OIDC SDK for Xamarin
https://github.com/okta/okta-oidc-xamarin
Apache License 2.0
10 stars 11 forks source link

OKTA-417977: correct handling of authserver id on revoke and renew #59

Closed bryanapellanes-okta closed 3 years ago

bryanapellanes-okta commented 3 years ago

When complete, this resolves #58

bryanapellanes-okta commented 3 years ago

I'll need to rebase this once #56 is merged.

NiranjanXamarin commented 2 years ago

I am facing this issue while getting refresh token. I am using Okta.Xamarin 3.1.0 (latest). I stored the token in preferences while login and then using the same for renew. But its giving exception as object reference error instead of providing status code and error message.

var refreshToken = Preferences.Get(PreferencesKey.RefreshToken, string.Empty); var renewedToken = await OktaContext.Current.RenewAsync(refreshToken);

as per documentations the method should be call like following 

var renewedToken = await OktaContext.Current.RenewAsync(TokenKind.AccessToken);

but this method not accepting this argument.Please help.

bryanapellanes-okta commented 2 years ago

@NiranjanXamarin

var renewedToken = await OktaContext.Current.RenewAsync(refreshToken);

This is the correct way to call the RenewAsync method; the documentation you reference is likely wrong and should be corrected. Please provide a link to the documentation that shows the method receives a TokenKind.AccessToken argument and we will be certain to correct it. I apologize for the inconvenience.

NiranjanXamarin commented 2 years ago

Thanks a lot for your reply, but my issue remains the same. exception as object reference error instead of providing status code and error message. when I try to get a refresh token for the second time.

for the document need an update is here, https://github.com/okta/okta-oidc-xamarin

bryanapellanes-okta commented 2 years ago

Thanks a lot for your reply, but my issue remains the same. exception as object reference error instead of providing status code and error message. when I try to get a refresh token for the second time.

Please provide minimum code and steps to reproduce the error you are seeing.

NiranjanXamarin commented 2 years ago

I am using okta.Xamarin(3.1.0). 
configured the file in asset folder inside android project with following content :


<?xml version="1.0" encoding="UTF-8" ?>
<Okta>
    <ClientId>client Id</ClientId>
    <OktaDomain>domainn url</OktaDomain>
    <RedirectUri>redirect url</RedirectUri>
    <PostLogoutRedirectUri>logout url</PostLogoutRedirectUri>
    <Scope>openid profile offline_access</Scope>
</Okta>

used await OktaContext.Current.SignInAsync(); this method to get access token , id token and refresh token.
saved all information in preferences.

then added a custom login to check if the access token is expired or not like following


Preferences.Get(PreferencesKey.ExpiryTime, DateTime.UtcNow)< DateTime.UtcNow.AddMinutes(5);

and then if the access token has expired then called renew token by passing stored refresh token 
await OktaContext.Current.RenewAsync(refreshToken);

this time I am getting response with refresh token and the expiresIn seconds , so I Updated both values in preferences like:

expiresIn = DateTime.UtcNow.AddSeconds(renewedToken.ExpiresIn); RefreshToken = renewedToken.RefreshToken;



Now , after the expiration of this new refresh token that means (3600) when aI tries to get new refresh token with 
await OktaContext.Current.RenewAsync(refreshToken); I am getting a response with null values and the exception of object reference not set

bryanapellanes-okta commented 2 years ago

@NiranjanXamarin I apologize for the inconvenience. I've entered an internal issue to review the issue you describe and provide a fix. This will need to be prioritized against other work.

Internal Ref: OKTA-535318

NiranjanXamarin commented 2 years ago

@bryanapellanes-okta thanks alot for prioritising this. Appreciated your quick action.