Skip to content

Commit

Permalink
Fix mobile auth bug (#700)
Browse files Browse the repository at this point in the history
* Removed token expiration check

* Bump versions so we can deploy auth fix
  • Loading branch information
matt-goldman authored Feb 21, 2024
1 parent 681bf51 commit 98a6738
Show file tree
Hide file tree
Showing 3 changed files with 5 additions and 28 deletions.
2 changes: 1 addition & 1 deletion src/MobileUI/Platforms/Android/AndroidManifest.xml
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android" package="com.ssw.consulting" android:versionCode="44" android:versionName="3.0.7">
<manifest xmlns:android="http://schemas.android.com/apk/res/android" package="com.ssw.consulting" android:versionCode="45" android:versionName="3.0.8">
<application android:allowBackup="true" android:icon="@mipmap/icon_dark" android:supportsRtl="true" android:label="SSW Rewards"></application>
<!-- Setting Targeted sdk version to 32 instead of the latest 33 due to Android Permissions not correctly implemented yet
See Issue: https://github.com/dotnet/maui/issues/11275 -->
Expand Down
2 changes: 1 addition & 1 deletion src/MobileUI/Platforms/iOS/Info.plist
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@
<key>CFBundleVersion</key>
<string>2</string>
<key>CFBundleShortVersionString</key>
<string>3.0.7</string>
<string>3.0.8</string>
<key>ITSAppUsesNonExemptEncryption</key>
<false/>
</dict>
Expand Down
29 changes: 3 additions & 26 deletions src/MobileUI/Services/IAuthenticationService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -186,33 +186,13 @@ private async Task SettRefreshToken(AuthResult result)
RefreshToken = result.RefreshToken;
await SecureStorage.SetAsync(nameof(RefreshToken), RefreshToken);
}

if (result.RefreshTokenExpiration.HasValue)
{
_refreshTokenExpiry = result.RefreshTokenExpiration.Value;
Preferences.Set(nameof(_refreshTokenExpiry), _refreshTokenExpiry.ToUnixTimeSeconds());
}
else
{
Preferences.Remove(nameof(_refreshTokenExpiry));
}
}

public async Task<bool> RefreshLoginAsync()
{
RefreshToken = await SecureStorage.GetAsync(nameof(RefreshToken));

var refreshTokenExpiry = Preferences.Get(nameof(_refreshTokenExpiry), 0L);

bool refreshTokenExpired = false;

if (refreshTokenExpiry > 0)
{
_refreshTokenExpiry = DateTimeOffset.FromUnixTimeSeconds(refreshTokenExpiry);
refreshTokenExpired = _refreshTokenExpiry < DateTimeOffset.Now.AddMinutes(2);
}

if (!string.IsNullOrWhiteSpace(RefreshToken) && !refreshTokenExpired)
if (!string.IsNullOrWhiteSpace(RefreshToken))
{
var oidcClient = new OidcClient(_options);

Expand Down Expand Up @@ -275,8 +255,7 @@ private AuthResult GetAuthResult<TResult> (TResult result)
AccessToken = loginResult.AccessToken,
RefreshToken = loginResult.RefreshToken,
AccessTokenExpiration = loginResult.AccessTokenExpiration,
IdentityToken = loginResult.IdentityToken,
RefreshTokenExpiration = null
IdentityToken = loginResult.IdentityToken
};
}
else if (result is RefreshTokenResult refreshTokenResult)
Expand All @@ -286,8 +265,7 @@ private AuthResult GetAuthResult<TResult> (TResult result)
AccessToken = refreshTokenResult.AccessToken,
RefreshToken = refreshTokenResult.RefreshToken,
IdentityToken = refreshTokenResult.IdentityToken,
AccessTokenExpiration = refreshTokenResult.AccessTokenExpiration,
RefreshTokenExpiration = DateTimeOffset.UtcNow.AddSeconds(refreshTokenResult.ExpiresIn)
AccessTokenExpiration = refreshTokenResult.AccessTokenExpiration
};
}
else
Expand All @@ -302,7 +280,6 @@ private class AuthResult
public string RefreshToken { get; set; }
public string IdentityToken { get; set; }
public DateTimeOffset AccessTokenExpiration { get; set; }
public DateTimeOffset? RefreshTokenExpiration { get; set; }
}
}

Expand Down

0 comments on commit 98a6738

Please sign in to comment.