Skip to content

Commit 2454208

Browse files
authored
Merge pull request xmartlabs#51 from xmartlabs/refactor/swift_support_email_token
Refactor/ios_android_common_interface.
2 parents c25a475 + 1939106 commit 2454208

File tree

17 files changed

+1452
-407
lines changed

17 files changed

+1452
-407
lines changed

.babelrc

Lines changed: 0 additions & 12 deletions
This file was deleted.

.eslintignore

Lines changed: 0 additions & 1 deletion
This file was deleted.

.eslintrc

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
{
2+
"root": true,
3+
"extends": [
4+
"@react-native-community",
5+
"plugin:prettier/recommended",
6+
"prettier"
7+
],
8+
"parser": "@typescript-eslint/parser",
9+
"plugins": [
10+
"@typescript-eslint",
11+
"simple-import-sort",
12+
"sort-keys-fix",
13+
"prettier"
14+
],
15+
"rules": {
16+
"prettier/prettier": "error",
17+
"sort-keys-fix/sort-keys-fix": "warn",
18+
"semi": ["off"],
19+
"simple-import-sort/sort": "error",
20+
"no-console": ["error", { "allow": ["warn"] }],
21+
"sort-keys": "error",
22+
"sort-imports": "off",
23+
"import/order": "off"
24+
}
25+
}

.eslintrc.js

Lines changed: 0 additions & 9 deletions
This file was deleted.

.gitignore

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -66,3 +66,5 @@ buck-out/
6666
# CocoaPods
6767
/ios/Pods/
6868
/example/ios/Pods/
69+
70+
dist/

.prettierignore

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
package.json
2+
ios

README.md

Lines changed: 32 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,8 @@ Inside your `AppDelegate.m`, setup the line sdk by passing the channel id obtain
6161
1. Add `platform :ios, '10.0'` in `Podfile` line:1
6262
2. Enable `use_frameworks!` in `Podfile` line:3
6363
3. Comment the code related to flipper, flipper doesn't support `use_frameworks!` !
64-
4. Add this code to your `AppDelegate.m`
64+
4. Modify your info.plist like it says here [Configuring the Info.plist file](https://developers.line.biz/en/docs/ios-sdk/swift/setting-up-project/#configuring-the-info-plist-file)
65+
5. Add this code to your `AppDelegate.m`
6566

6667
```objc
6768
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
@@ -121,15 +122,15 @@ import LineLogin from '@xmartlabs/react-native-line'
121122

122123
Then, you can start using all the functions that are available:
123124

124-
| Function | Description |
125-
| ------------------------------------------------------- | ---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
126-
| `login(args?: LoginArguments): Promise<LoginResult>` | Starts the login flow of Line's SDK (Opens the apps if it's installed and defaults to the browser otherwise). It accepts the same argumements as the LineSDK, in an object `{ key: value }`, defaults the same way as LineSDK too. |
127-
| `getCurrentAccessToken(): Promise<AccessToken>` | Returns the current access token for the currently logged in user. |
128-
| `getProfile(): Promise<UserProfile>` | Returns the profile of the currently logged in user. |
129-
| `logout(): Promise<void>` | Logs out the currently logged in user. |
130-
| `refreshToken(): Promise<AccessToken>` | Refreshes the access token and returns it. |
131-
| `verifyAccessToken(): Promise<AccessTokenVerifyResult>` | Verifies the access token and returns it. |
132-
| `getBotFriendshipStatus(): Promise<any>` | Gets bot friendship status if [configured](https://developers.line.biz/en/docs/ios-sdk/swift/link-a-bot/). |
125+
| Function | Description |
126+
| -------------------------------------------------------- | ---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
127+
| `login(args?: LoginArguments): Promise<LoginResult>` | Starts the login flow of Line's SDK (Opens the apps if it's installed and defaults to the browser otherwise). It accepts the same argumements as the LineSDK, in an object `{ key: value }`, defaults the same way as LineSDK too. |
128+
| `getCurrentAccessToken(): Promise<AccessToken>` | Returns the current access token for the currently logged in user. |
129+
| `getProfile(): Promise<UserProfile>` | Returns the profile of the currently logged in user. |
130+
| `logout(): Promise<void>` | Logs out the currently logged in user. |
131+
| `refreshToken(): Promise<AccessToken>` | Refreshes the access token and returns it. |
132+
| `verifyAccessToken(): Promise<AccessTokenVerifyResult>` | Verifies the access token and returns it. |
133+
| `getBotFriendshipStatus(): Promise<BotFriendshipStatus>` | Gets bot friendship status if [configured](https://developers.line.biz/en/docs/ios-sdk/swift/link-a-bot/). |
133134

134135
### Return values
135136

@@ -139,40 +140,34 @@ The following objects are returned on the methods described above:
139140

140141
```typescript
141142
{
142-
/// The user ID of the current authorized user.
143+
/// The user ID of the current authorized user.
143144
userID: String
144145

145146
/// The display name of the current authorized user.
146-
displayName: String
147+
displayName: string
147148

148149
/// The profile image URL of the current authorized user. `null` if the user has not set a profile
149150
/// image.
150-
pictureURL?: URL
151-
152-
/// The large profile image URL of the current authorized user. `null` if the user has not set a profile
153-
/// image.
154-
pictureURLLarge?: URL
155-
156-
/// The small profile image URL of the current authorized user. `null` if the user has not set a profile
157-
/// image.
158-
pictureURLSmall?: URL
151+
pictureURL?: string
159152

160153
/// The status message of the current authorized user. `null` if the user has not set a status message.
161-
statusMessage?: String
154+
statusMessage?: string
162155
}
163156
```
164157

165158
2. AccessToken:
166159

167160
```typescript
168161
{
169-
/// The value of the access token.
162+
/// The value of the access token.
170163
access_token: String
171-
172164
/// The expiration time of the access token. It is calculated using `createdAt` and the validity period
173165
/// of the access token. This value might not be the actual expiration time because this value depends
174166
/// on the system time of the device when `createdAt` is determined.
175167
expires_in: String
168+
/// The raw string value of the ID token bound to the access token. The value exists only if the access token
169+
/// is obtained with the `.openID` permission.
170+
id_token?: String
176171
}
177172
```
178173

@@ -195,7 +190,7 @@ The following objects are returned on the methods described above:
195190

196191
```typescript
197192
{
198-
/// The access token obtained by the login process.
193+
/// The access token obtained by the login process.
199194
accessToken: AccessToken
200195
/// The permissions bound to the `accessToken` object by the authorization process. Scope has them separated by spaces
201196
scope: String
@@ -207,15 +202,20 @@ The following objects are returned on the methods described above:
207202
/// `LoginManagerOption` object when the user logs in. For more information, see Linking a bot with your LINE
208203
/// Login channel at https://developers.line.me/en/docs/line-login/web/link-a-bot/.
209204
friendshipStatusChanged?: boolean
210-
/// The raw string value of the ID token bound to the access token. The value exists only if the access token
211-
/// is obtained with the `.openID` permission.
212-
lineIdToken?: String
213205
/// The `nonce` value when requesting ID Token during login process. Use this value as a parameter when you
214206
/// verify the ID Token against the LINE server. This value is `null` if `.openID` permission is not requested.
215207
IDTokenNonce?: String
216208
}
217209
```
218210

211+
5. BotFriendshipStatus
212+
213+
```typescript
214+
{
215+
friendFlag: boolean
216+
}
217+
```
218+
219219
### Arguments
220220

221221
1. LoginArguments
@@ -232,21 +232,21 @@ The following objects are returned on the methods described above:
232232

233233
```typescript
234234
{
235-
email = 'email',
235+
EMAIL = 'email',
236236
/// The permission to get an ID token in the login response.
237-
openID = 'openid',
237+
OPEN_ID = 'openid',
238238

239239
/// The permission to get the user's profile including the user ID, display name, and the profile image
240240
/// URL in the login response.
241-
profile = 'profile',
241+
PROFILE = 'profile',
242242
}
243243
```
244244

245245
3. BotPrompt
246246

247247
```typescript
248248
{
249-
agressive = 'agressive',
249+
aggressive = 'aggressive',
250250
normal = 'normal',
251251
}
252252
```

android/src/main/java/com/xmartlabs/rnline/RNLine.kt

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -175,7 +175,7 @@ class RNLine(reactContext: ReactApplicationContext) : ReactContextBaseJavaModule
175175
fun getCurrentAccessToken(promise: Promise) = invokeLineServiceMethod(
176176
promise = promise,
177177
serviceCallable = { lineApiClient.currentAccessToken },
178-
parser = { parseAccessToken(it) }
178+
parser = { parseAccessToken(it, lineIdToken = null) }
179179
)
180180

181181
@ReactMethod
@@ -189,7 +189,7 @@ class RNLine(reactContext: ReactApplicationContext) : ReactContextBaseJavaModule
189189
fun refreshToken(promise: Promise) = invokeLineServiceMethod(
190190
promise = promise,
191191
serviceCallable = { lineApiClient.refreshAccessToken() },
192-
parser = { parseAccessToken(it) }
192+
parser = { parseAccessToken(it, lineIdToken = null) }
193193
)
194194

195195
@ReactMethod
@@ -219,10 +219,11 @@ class RNLine(reactContext: ReactApplicationContext) : ReactContextBaseJavaModule
219219
}
220220

221221
// Parsers
222-
private fun parseAccessToken(accessToken: LineAccessToken): WritableMap = Arguments.makeNativeMap(
222+
private fun parseAccessToken(accessToken: LineAccessToken, lineIdToken: LineIdToken?): WritableMap = Arguments.makeNativeMap(
223223
mapOf(
224224
"access_token" to accessToken.tokenString,
225-
"expires_in" to accessToken.expiresInMillis
225+
"expires_in" to accessToken.expiresInMillis,
226+
"id_token" to lineIdToken?.rawString
226227
)
227228
)
228229

@@ -232,7 +233,7 @@ class RNLine(reactContext: ReactApplicationContext) : ReactContextBaseJavaModule
232233
)
233234
)
234235

235-
private fun parseVerifyAccessToken(verifyAccessToken: LineCredential): WritableMap = Arguments.makeNativeMap(
236+
private fun parseVerifyAccessToken( verifyAccessToken: LineCredential): WritableMap = Arguments.makeNativeMap(
236237
mapOf(
237238
"client_id" to channelId,
238239
"scope" to Scope.join(verifyAccessToken.scopes),
@@ -253,11 +254,10 @@ class RNLine(reactContext: ReactApplicationContext) : ReactContextBaseJavaModule
253254
private fun parseLoginResult(loginResult: LineLoginResult): WritableMap = Arguments.makeNativeMap(
254255
mapOf(
255256
"userProfile" to parseProfile(loginResult.lineProfile!!),
256-
"accessToken" to parseAccessToken(loginResult.lineCredential!!.accessToken),
257+
"accessToken" to parseAccessToken(loginResult.lineCredential!!.accessToken, loginResult.lineIdToken),
257258
"scope" to loginResult.lineCredential?.scopes?.let {
258259
Scope.join(it)
259260
},
260-
"lineIdToken" to loginResult.lineIdToken?.rawString,
261261
"friendshipStatusChanged" to loginResult.friendshipStatusChanged,
262262
"IDTokenNonce" to loginResult.lineIdToken?.nonce
263263
)

index.js

Lines changed: 0 additions & 39 deletions
This file was deleted.

ios/LineLogin.swift

Lines changed: 18 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -40,31 +40,32 @@ import LineSDK
4040
LineLogin.nilArgument(reject)
4141
return
4242
}
43-
print(args)
43+
4444
let scopes = (args["scopes"] as? [String])?.map { LoginPermission(rawValue: $0) } ?? [.profile]
4545
let onlyWebLogin = (args["onlyWebLogin"] as? Bool) ?? false
46-
47-
var options: LoginManagerOptions = []
48-
if onlyWebLogin { options = .onlyWebLogin }
46+
var parameters: LoginManager.Parameters = LoginManager.Parameters.init()
47+
48+
if onlyWebLogin { parameters.onlyWebLogin = onlyWebLogin }
4949

5050
if let botPrompt = args["botPrompt"] as? String {
5151
switch botPrompt {
52-
case "aggressive": options.insert(.botPromptAggressive)
53-
case "normal": options.insert(.botPromptNormal)
52+
case "aggressive": parameters.botPromptStyle = LoginManager.BotPrompt(rawValue: "aggresive")
53+
case "normal": parameters.botPromptStyle = LoginManager.BotPrompt(rawValue: "normal")
5454
default: break
5555
}
5656
}
57-
58-
LoginManager.shared.login(
59-
permissions: Set(scopes),
60-
in: nil,
61-
options: options) { result in
62-
switch result {
63-
case .success(let value): value.resolver(resolve, reject, name: "login")
64-
case .failure(let error): error.rejecter(reject)
57+
58+
DispatchQueue.main.async {
59+
LoginManager.shared.login(
60+
permissions: Set(scopes),
61+
in: nil,
62+
parameters: parameters) { result in
63+
switch result {
64+
case .success(let value): value.resolver(resolve, reject, name: "login")
65+
case .failure(let error): error.rejecter(reject)
66+
}
6567
}
6668
}
67-
6869
}
6970

7071
@objc func logout(_ resolve: @escaping RCTPromiseResolveBlock,
@@ -100,7 +101,7 @@ import LineSDK
100101

101102
@objc func refreshToken(_ resolve: @escaping RCTPromiseResolveBlock,
102103
rejecter reject: @escaping RCTPromiseRejectBlock) {
103-
API.refreshAccessToken { result in
104+
API.Auth.refreshAccessToken { result in
104105
switch result {
105106
case .success(let token): token.resolver(resolve, reject, name: "refresh token")
106107
case .failure(let error): error.rejecter(reject)
@@ -110,7 +111,7 @@ import LineSDK
110111

111112
@objc func verifyAccessToken(_ resolve: @escaping RCTPromiseResolveBlock,
112113
rejecter reject: @escaping RCTPromiseRejectBlock) {
113-
API.verifyAccessToken { result in
114+
API.Auth.verifyAccessToken { result in
114115
switch result {
115116
case .success(let token): token.resolver(resolve, reject, name: "verify token")
116117
case .failure(let error): error.rejecter(reject)

0 commit comments

Comments
 (0)