Skip to content

Commit 2023ab2

Browse files
author
Michael Oberwasserlechner
authored
Merge pull request #27 from moberwasserlechner/develop
Beta 2 features
2 parents f2bad47 + 3a3506b commit 2023ab2

File tree

16 files changed

+954
-618
lines changed

16 files changed

+954
-618
lines changed

ByteowlsCapacitorOauth2.podspec

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ require 'json'
1212
s.author = package['author']
1313
s.ios.deployment_target = '11.0'
1414
s.dependency 'Capacitor', '1.0.0-beta.16'
15-
s.dependency 'OAuthSwift', '1.2.2'
15+
s.dependency 'OAuthSwift', '1.3.0'
1616
s.source = { :git => 'https://github.com/moberwasserlechner/capacitor-oauth2', :tag => s.version.to_s }
1717
s.source_files = 'ios/ByteowlsCapacitorOauth2/Source/*.{swift,h,m}'
1818
s.swift_version = '4.2'

README.md

Lines changed: 21 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,9 +18,11 @@ Status: **ok**
1818

1919
### Authorization code flow + PKCE
2020

21-
Status: **planned** see #4
21+
Status: **ok**
22+
23+
Please be aware that some providers (OneDrive, Auth0) allow Code Flow + PKCE only for native apps. Web apps have to use implicit flow.
2224

23-
**Attention:**
25+
### Important
2426
For security reasons this plugin does not support the authorization code flow without PKCE.
2527

2628
That would include storing your **client secret** in client code which is highly insecure and not recommended.
@@ -96,6 +98,23 @@ export class SignupComponent {
9698

9799
See the `oauth2Options` interface at https://github.com/moberwasserlechner/capacitor-oauth2/blob/master/src/definitions.ts#L24
98100

101+
### Error Codes
102+
103+
* ERR_PARAM_NO_APP_ID ... The appId / clientId is missing. (web, android, ios)
104+
* ERR_PARAM_NO_AUTHORIZATION_BASE_URL ... The authorization base url is missing. (web, android, ios)
105+
* ERR_PARAM_NO_REDIRECT_URL ... The redirect url / custom scheme url is missing. (web, android, ios)
106+
* ERR_PARAM_NO_ACCESS_TOKEN_ENDPOINT ... The access token endpoint url is missing. It is only needed if code flow is used. (web, android, ios)
107+
* ERR_PARAM_INVALID_RESPONSE_TYPE ... You configured a invalid responseType. Only "token" or "code" are allowed. (web, android, ios)
108+
* ERR_NO_ACCESS_TOKEN ... No access_token found. (web, android)
109+
* ERR_NO_AUTHORIZATION_CODE ... No authorization code was returned in the redirect response. (web, android, ios)
110+
* ERR_STATES_NOT_MATCH ... The state included in the authorization code request does not match the one in the redirect. Security risk! (web, android, ios)
111+
* USER_CANCELLED ... The user cancelled the login flow. (android, ios)
112+
* ERR_CUSTOM_HANDLER_LOGIN ... Login through custom handler class failed. See logs and check your code. (android, ios)
113+
* ERR_CUSTOM_HANDLER_LOGOUT ... Logout through custom handler class failed. See logs and check your code. (android, ios)
114+
* ERR_ANDROID_NO_BROWSER ... On Android not suitable browser could be found! (android)
115+
* ERR_GENERAL ... A unspecific error. Check the logs to see want exactly happened. (web, android, ios)
116+
117+
99118
## Platform: Web/PWA
100119

101120
This implementation just opens a browser window to let users enter their credentials.

android/@byteowls/capacitor-oauth2/src/main/java/com/byteowls/capacitor/oauth2/ConfigUtils.java

Lines changed: 29 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,9 @@
44
import com.getcapacitor.PluginCall;
55
import org.json.JSONObject;
66

7+
import java.util.HashMap;
8+
import java.util.Iterator;
9+
import java.util.Map;
710
import java.util.Random;
811

912
/**
@@ -28,7 +31,7 @@ public static <T> T getCallParam(Class<T> clazz, PluginCall call, String key, T
2831
if (clazz.isAssignableFrom(String.class)) {
2932
value = o.getString(k);
3033
} else if (clazz.isAssignableFrom(Boolean.class)) {
31-
value = o.getBoolean(k);
34+
value = o.optBoolean(k);
3235
} else if (clazz.isAssignableFrom(Double.class)) {
3336
value = o.getDouble(k);
3437
} else if (clazz.isAssignableFrom(Integer.class)) {
@@ -49,6 +52,31 @@ public static <T> T getCallParam(Class<T> clazz, PluginCall call, String key, T
4952
return defaultValue;
5053
}
5154

55+
public static Map<String, String> getCallParamMap(PluginCall call, String key) {
56+
Map<String, String> map = new HashMap<>();
57+
String k = getDeepestKey(key);
58+
try {
59+
JSONObject o = getDeepestObject(call.getData(), key);
60+
JSONObject jsonObject = o.getJSONObject(k);
61+
if (jsonObject != null) {
62+
Iterator<String> keys = jsonObject.keys();
63+
if (keys != null) {
64+
while (keys.hasNext()) {
65+
String mapKey = keys.next();
66+
if (mapKey != null && mapKey.trim().length() > 0) {
67+
String mapValue = jsonObject.getString(mapKey);
68+
if (mapValue != null && mapValue.trim().length() > 0) {
69+
map.put(mapKey, mapValue);
70+
}
71+
}
72+
}
73+
}
74+
75+
}
76+
} catch (Exception ignore) {}
77+
return map;
78+
}
79+
5280
public static String getDeepestKey(String key) {
5381
String[] parts = key.split("\\.");
5482
if (parts.length > 0) {

0 commit comments

Comments
 (0)