Skip to content

Commit

Permalink
custom claim tested
Browse files Browse the repository at this point in the history
  • Loading branch information
romme86 committed May 20, 2022
1 parent 0576c59 commit 24ce7ae
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 12 deletions.
4 changes: 2 additions & 2 deletions vidaia/lib/pages/home/home_page_loader.dart
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ class _HomePage2State extends State<HomePage2> {
isDataLoaded, //Future that returns bool
]),
builder: (BuildContext context, AsyncSnapshot<List<bool>> snapshot) {
if (snapshot.connectionState == ConnectionState.done && AuthService.instance.profile!.id.isNotEmpty && snapshot.data?[0] == true) {
if (snapshot.connectionState == ConnectionState.done && AuthService.instance.profile != null && AuthService.instance.profile!.id.isNotEmpty && snapshot.data?[0] == true) {
return HomePageStack(_pages);
} else if (snapshot.connectionState == ConnectionState.done && snapshot.hasError) {
return Padding(
Expand All @@ -49,7 +49,7 @@ class _HomePage2State extends State<HomePage2> {
style: TextStyle(fontSize: 20),
),
);
} else if (snapshot.data?[0] == false) {
} else if (AuthService.instance.profile == null || AuthService.instance.profile!.id.isEmpty) {
return const LoginPage();
} else {
return Center(
Expand Down
25 changes: 15 additions & 10 deletions vidaia/lib/services/auth_service.dart
Original file line number Diff line number Diff line change
Expand Up @@ -64,8 +64,7 @@ class AuthService {
headers: {'Authorization': 'Bearer $auth0AccessToken'},
);

debugPrint(
'logout: ${response.request} ${response.statusCode} ${response.body}');
debugPrint('logout: ${response.request} ${response.statusCode} ${response.body}');

return 'logout: ${response.request} ${response.statusCode} ${response.body}';
}
Expand All @@ -82,8 +81,7 @@ class AuthService {
/// possible values login, none, consent, select_account
);

final AuthorizationTokenResponse? result =
await appAuth.authorizeAndExchangeCode(
final AuthorizationTokenResponse? result = await appAuth.authorizeAndExchangeCode(
authorizationTokenRequest,
);

Expand Down Expand Up @@ -111,28 +109,35 @@ class AuthService {
}

Future<Auth0User> getUserDetails(String accessToken) async {
Auth0User auth0user;

final url = Uri.https(
AUTH0_DOMAIN,
'/userinfo',
);

final response = await http.get(
final responseAuth0UserInfo = await http.get(
url,
headers: {'Authorization': 'Bearer $accessToken'},
);

print('getUserDetails ${response.body}');
print('getUserDetails ${responseAuth0UserInfo.body}');

if (responseAuth0UserInfo.statusCode == 200) {
auth0user = Auth0User.fromJson(jsonDecode(responseAuth0UserInfo.body));
} else {
throw Exception('Failed to get user details');
}

if (response.statusCode == 200) {
return Auth0User.fromJson(jsonDecode(response.body));
if (responseAuth0UserInfo.statusCode == 200) {
return auth0user;
} else {
throw Exception('Failed to get user details');
}
}

Future<String> _setLocalVariables(result) async {
final bool isValidResult =
result != null && result.accessToken != null && result.idToken != null;
final bool isValidResult = result != null && result.accessToken != null && result.idToken != null;

if (isValidResult) {
auth0AccessToken = result.accessToken;
Expand Down

0 comments on commit 24ce7ae

Please sign in to comment.