-
Notifications
You must be signed in to change notification settings - Fork 10
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Using environment variables now. Pulling jwks from Cognito
- Loading branch information
Vladimir Budilov
committed
Jan 7, 2018
1 parent
7f094fc
commit d50b9f3
Showing
16 changed files
with
215 additions
and
102 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -9,4 +9,5 @@ gradlew.bat | |
repo/ | ||
.idea/ | ||
out/ | ||
nohup.out | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Binary file not shown.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,6 @@ | ||
#Wed Nov 09 21:55:11 EST 2016 | ||
#Wed Dec 27 10:28:42 EST 2017 | ||
distributionBase=GRADLE_USER_HOME | ||
distributionPath=wrapper/dists | ||
zipStoreBase=GRADLE_USER_HOME | ||
zipStorePath=wrapper/dists | ||
distributionUrl=https\://services.gradle.org/distributions/gradle-3.2-all.zip | ||
distributionUrl=https\://services.gradle.org/distributions/gradle-4.0-bin.zip |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,20 +1,16 @@ | ||
package com.budilov.cognito | ||
|
||
import com.google.gson.GsonBuilder | ||
|
||
/** | ||
* Created by Vladimir Budilov | ||
* https://cognito-idp.{region}.amazonaws.com/{userPoolId}/.well-known/jwks.json --> | ||
* | ||
* https://cognito-idp.us-east-1.amazonaws.com/us-east-1_PGSbCVZ7S/.well-known/jwks.json | ||
*/ | ||
data class Properties(val regionName: String, val cognitoUserPoolId: String, | ||
val cognitoClientId: String, val jwtIdTokenKid: String) | ||
|
||
object PropertyFileConverter { | ||
object Properties { | ||
|
||
internal fun readCredentials(): Properties { | ||
val gson = GsonBuilder().create() | ||
return gson.fromJson(PropertyFileConverter.javaClass.classLoader.getResource("properties.json").readText(), Properties::class.java) | ||
} | ||
} | ||
val regionName: String = System.getenv("REGION_NAME") | ||
val cognitoUserPoolId: String = System.getenv("COGNITO_USER_POOL_ID") | ||
val cognitoAppClientId: String = System.getenv("COGNITO_APP_CLIENT_ID") | ||
val jwksUrl = "https://cognito-idp.$regionName.amazonaws.com/$cognitoUserPoolId/.well-known/jwks.json" | ||
val jwtTokenIssuer = "https://cognito-idp.$regionName.amazonaws.com/$cognitoUserPoolId" | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
43 changes: 43 additions & 0 deletions
43
src/main/kotlin/com/budilov/cognito/lambda/CognitoRefreshTokensLambda.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
package com.budilov.cognito.lambda | ||
|
||
import com.amazonaws.services.lambda.runtime.Context | ||
import com.amazonaws.services.lambda.runtime.RequestHandler | ||
import com.budilov.cognito.services.cognito.CognitoService | ||
import com.google.gson.Gson | ||
|
||
class CognitoRefreshTokensLambda : RequestHandler<ApiGatewayRequest.Input, | ||
CognitoRefreshTokensLambda.AuthResponse> { | ||
|
||
data class AuthResponse(val statusCode: Int, | ||
val body: String) | ||
|
||
val cognito = CognitoService() | ||
|
||
/** | ||
* 1. Get the request from API Gateway. Unmarshal (automatically) the request | ||
* 2. Get the | ||
*/ | ||
override fun handleRequest(request: ApiGatewayRequest.Input?, | ||
context: Context?): AuthResponse? { | ||
val logger = context?.logger | ||
|
||
val refreshToken = request?.headers?.get("refreshToken") | ||
|
||
logger?.log("${refreshToken}") | ||
var status = 400 | ||
val resultBody = if (refreshToken != null) { | ||
status = 200 | ||
|
||
val response = cognito.adminRefreshTokens(refreshToken = refreshToken) | ||
|
||
Gson().toJson(response) | ||
} else { | ||
logger?.log("Username and password are required") | ||
"Username and password are required" | ||
} | ||
|
||
logger?.log("request payload: " + Gson().toJson(request)) | ||
|
||
return AuthResponse(status, resultBody) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.