Skip to content

Commit 33ebc35

Browse files
authored
Merge pull request #50 from line/feature/settable-nonce
Add settable nonce
2 parents 3b0768c + f25b7f2 commit 33ebc35

File tree

10 files changed

+27
-16
lines changed

10 files changed

+27
-16
lines changed

android/build.gradle

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ buildscript {
99
}
1010

1111
dependencies {
12-
classpath 'com.android.tools.build:gradle:3.3.1'
12+
classpath 'com.android.tools.build:gradle:7.0.1'
1313
classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version"
1414
}
1515

android/gradle/wrapper/gradle-wrapper.properties

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,4 +3,4 @@ distributionBase=GRADLE_USER_HOME
33
distributionPath=wrapper/dists
44
zipStoreBase=GRADLE_USER_HOME
55
zipStorePath=wrapper/dists
6-
distributionUrl=https\://services.gradle.org/distributions/gradle-5.1.1-all.zip
6+
distributionUrl=https\://services.gradle.org/distributions/gradle-7.2-all.zip

android/src/main/kotlin/com/linecorp/flutter_line_sdk/FlutterLineSdkPlugin.kt

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -63,13 +63,15 @@ class FlutterLineSdkPlugin : MethodCallHandler, PluginRegistry.ActivityResultLis
6363
val scopes = call.argument("scopes") ?: emptyList<String>()
6464
val isWebLogin = call.argument("onlyWebLogin") ?: false
6565
val botPrompt = call.argument("botPrompt") ?: "normal"
66+
val idTokenNonce: String? = call.argument("idTokenNonce")
6667
val loginRequestCode = call.argument<Int?>("loginRequestCode") ?: DEFAULT_ACTIVITY_RESULT_REQUEST_CODE
6768
lineSdkWrapper.login(
6869
loginRequestCode,
6970
activity,
7071
scopes = scopes,
7172
onlyWebLogin = isWebLogin,
7273
botPromptString = botPrompt,
74+
idTokenNonce = idTokenNonce,
7375
result = result
7476
)
7577
}

android/src/main/kotlin/com/linecorp/flutter_line_sdk/LineSdkWrapper.kt

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,7 @@ class LineSdkWrapper {
5555
scopes: List<String> = listOf("profile"),
5656
onlyWebLogin: Boolean = false,
5757
botPromptString: String = "normal",
58+
idTokenNonce: String? = null,
5859
result: Result
5960
) {
6061
runIfDebugBuild {
@@ -69,6 +70,7 @@ class LineSdkWrapper {
6970
.scopes(Scope.convertToScopeList(scopes))
7071
.apply {
7172
botPrompt(LineAuthenticationParams.BotPrompt.valueOf(botPromptString))
73+
idTokenNonce?.let { nonce(it) }
7274
}
7375
.build()
7476

example/android/app/src/profile/AndroidManifest.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
2-
package="com.linecorp.linesdk.example">
2+
package="com.linecorp.linesdk.sample">
33
<!-- Flutter needs it to communicate with the running application
44
to allow setting breakpoints, to provide hot reload, etc.
55
-->

example/android/build.gradle

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ buildscript {
66
}
77

88
dependencies {
9-
classpath 'com.android.tools.build:gradle:3.5.0'
9+
classpath 'com.android.tools.build:gradle:7.0.1'
1010
classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version"
1111
}
1212
}

example/android/gradle/wrapper/gradle-wrapper.properties

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,4 +3,4 @@ distributionBase=GRADLE_USER_HOME
33
distributionPath=wrapper/dists
44
zipStoreBase=GRADLE_USER_HOME
55
zipStorePath=wrapper/dists
6-
distributionUrl=https\://services.gradle.org/distributions/gradle-5.4.1-all.zip
6+
distributionUrl=https\://services.gradle.org/distributions/gradle-7.2-all.zip

ios/Classes/SwiftFlutterLineSdkPlugin.swift

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -130,23 +130,23 @@ extension LineChannelMethod {
130130
}
131131

132132
let scopes = (args["scopes"] as? [String])?.map { LoginPermission(rawValue: $0) } ?? [.profile]
133-
let onlyWebLogin = (args["onlyWebLogin"] as? Bool) ?? false
134-
135-
var options: LoginManagerOptions = []
136-
if onlyWebLogin { options = .onlyWebLogin }
137-
133+
134+
var parameters = LoginManager.Parameters()
135+
parameters.onlyWebLogin = (args["onlyWebLogin"] as? Bool) ?? false
136+
parameters.IDTokenNonce = args["idTokenNonce"] as? String
137+
138138
if let botPrompt = args["botPrompt"] as? String {
139139
switch botPrompt {
140-
case "aggressive": options.insert(.botPromptAggressive)
141-
case "normal": options.insert(.botPromptNormal)
140+
case "aggressive": parameters.botPromptStyle = .aggressive
141+
case "normal": parameters.botPromptStyle = .normal
142142
default: break
143143
}
144144
}
145145

146146
LoginManager.shared.login(
147147
permissions: Set(scopes),
148148
in: nil,
149-
options: options) { r in
149+
parameters: parameters) { r in
150150
switch r {
151151
case .success(let value): result(value.json)
152152
case .failure(let error): result(error.flutterError)
@@ -173,7 +173,7 @@ extension LineChannelMethod {
173173
}
174174

175175
func refreshToken(arguments: [String: Any]?, result: @escaping FlutterResult) {
176-
API.refreshAccessToken { r in
176+
API.Auth.refreshAccessToken { r in
177177
switch r {
178178
case .success(let value): result(value.json)
179179
case .failure(let error): result(error.flutterError)
@@ -182,7 +182,7 @@ extension LineChannelMethod {
182182
}
183183

184184
func verifyAccessToken(arguments: [String: Any]?, result: @escaping FlutterResult) {
185-
API.verifyAccessToken { r in
185+
API.Auth.verifyAccessToken { r in
186186
switch r {
187187
case .success(let value): result(value.json)
188188
case .failure(let error): result(error.flutterError)

lib/src/line_sdk.dart

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -100,7 +100,8 @@ class LineSDK {
100100
'loginRequestCode': option?.requestCode,
101101
'scopes': scopes,
102102
'onlyWebLogin': option?.onlyWebLogin,
103-
'botPrompt': option?.botPrompt
103+
'botPrompt': option?.botPrompt,
104+
'idTokenNonce': option?.idTokenNonce,
104105
}).then((value) => LoginResult._(_decodeJson(value)));
105106
}
106107

lib/src/model/login_option.dart

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,12 @@ class LoginOption {
4242
/// Request code that LINE login activity will be called with.
4343
int requestCode;
4444

45+
/// Sets the nonce value for ID token verification. This value is used when requesting user authorization
46+
/// with `.openID` permission to prevent replay attacks to your backend server. If not set, LINE SDK will
47+
/// generate a random value as the token nonce. Whether set or not, LINE SDK verifies against the nonce value
48+
/// in received ID token locally.
49+
String? idTokenNonce;
50+
4551
LoginOption(this.onlyWebLogin, this.botPrompt,
4652
{this.requestCode = DEFAULT_ACTIVITY_RESULT_REQUEST_CODE});
4753
}

0 commit comments

Comments
 (0)