Set up initial Lambda sturucture with Cognito

Create demo Lambda/Gateway pair with Cognito integration
This commit is contained in:
NMerz
2020-09-20 16:26:13 -04:00
parent 2b1ecbadef
commit f576307e0a
11 changed files with 129 additions and 8 deletions

11
Listify/Pipfile Normal file
View File

@@ -0,0 +1,11 @@
[[source]]
name = "pypi"
url = "https://pypi.org/simple"
verify_ssl = true
[dev-packages]
[packages]
[requires]
python_version = "3.8"

View File

@@ -94,7 +94,7 @@ Parameters:
userPoolGroupList:
Type: CommaDelimitedList
serviceName:
Type: String

View File

@@ -1,6 +1,6 @@
{
"identityPoolName": "listifyf4fad454_identitypool_f4fad454",
"allowUnauthenticatedIdentities": false,
"allowUnauthenticatedIdentities": true,
"resourceNameTruncated": "listiff4fad454",
"userPoolName": "listifyf4fad454_userpool_f4fad454",
"autoVerifiedAttributes": [

View File

@@ -6,5 +6,7 @@
"dependsOn": [],
"customAuth": false
}
}
},
"function": {},
"api": {}
}

View File

@@ -1,15 +1,15 @@
package com.example.listify;
import android.util.Log;
import com.amplifyframework.auth.AuthException;
import com.amplifyframework.auth.AuthSession;
import com.amplifyframework.auth.cognito.AWSCognitoAuthSession;
import com.amplifyframework.auth.options.AuthSignUpOptions;
import com.amplifyframework.auth.result.AuthSignInResult;
import com.amplifyframework.auth.result.AuthSignUpResult;
import com.amplifyframework.core.Amplify;
public class AuthManager {
AuthSession authSession = null;
AWSCognitoAuthSession authSession = null;
AuthSignUpResult authSignUpResult = null;
AuthSignInResult authSignInResult = null;
AuthException authError = null;
@@ -27,14 +27,21 @@ public class AuthManager {
throwIfAuthError();
}
public AuthSession getAuthSession() throws AuthException {
fetchAuthSession();
public AWSCognitoAuthSession getAuthSession() throws AuthException {
if (authSession == null) {
fetchAuthSession();
}
return authSession;
}
public String getUserToken() {
return authSession.getUserPoolTokens().getValue().getIdToken();
}
public void setAuthSession(AuthSession toSet) {
authSession = toSet;
authSession = (AWSCognitoAuthSession) toSet;
waiting = false;
}

View File

@@ -35,6 +35,7 @@ public class MainActivity extends AppCompatActivity {
try {
authManager.signIn("merzn@purdue.edu", "Password123");
Log.i("Authentication", authManager.getAuthSession().toString());
Log.i("Token", authManager.getAuthSession().getUserPoolTokens().getValue().getIdToken());
} catch (AuthException e) {
Log.i("Authentication", "Login failed. User probably needs to register. Exact error: " + e.getMessage());
try {