Skip to content

Commit

Permalink
Merge pull request #27 from moberwasserlechner/develop
Browse files Browse the repository at this point in the history
Beta 2 features
  • Loading branch information
Michael Oberwasserlechner authored Mar 4, 2019
2 parents f2bad47 + 3a3506b commit 2023ab2
Show file tree
Hide file tree
Showing 16 changed files with 954 additions and 618 deletions.
2 changes: 1 addition & 1 deletion ByteowlsCapacitorOauth2.podspec
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ require 'json'
s.author = package['author']
s.ios.deployment_target = '11.0'
s.dependency 'Capacitor', '1.0.0-beta.16'
s.dependency 'OAuthSwift', '1.2.2'
s.dependency 'OAuthSwift', '1.3.0'
s.source = { :git => 'https://github.com/moberwasserlechner/capacitor-oauth2', :tag => s.version.to_s }
s.source_files = 'ios/ByteowlsCapacitorOauth2/Source/*.{swift,h,m}'
s.swift_version = '4.2'
Expand Down
23 changes: 21 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -18,9 +18,11 @@ Status: **ok**

### Authorization code flow + PKCE

Status: **planned** see #4
Status: **ok**

Please be aware that some providers (OneDrive, Auth0) allow Code Flow + PKCE only for native apps. Web apps have to use implicit flow.

**Attention:**
### Important
For security reasons this plugin does not support the authorization code flow without PKCE.

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

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

### Error Codes

* ERR_PARAM_NO_APP_ID ... The appId / clientId is missing. (web, android, ios)
* ERR_PARAM_NO_AUTHORIZATION_BASE_URL ... The authorization base url is missing. (web, android, ios)
* ERR_PARAM_NO_REDIRECT_URL ... The redirect url / custom scheme url is missing. (web, android, ios)
* 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)
* ERR_PARAM_INVALID_RESPONSE_TYPE ... You configured a invalid responseType. Only "token" or "code" are allowed. (web, android, ios)
* ERR_NO_ACCESS_TOKEN ... No access_token found. (web, android)
* ERR_NO_AUTHORIZATION_CODE ... No authorization code was returned in the redirect response. (web, android, ios)
* 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)
* USER_CANCELLED ... The user cancelled the login flow. (android, ios)
* ERR_CUSTOM_HANDLER_LOGIN ... Login through custom handler class failed. See logs and check your code. (android, ios)
* ERR_CUSTOM_HANDLER_LOGOUT ... Logout through custom handler class failed. See logs and check your code. (android, ios)
* ERR_ANDROID_NO_BROWSER ... On Android not suitable browser could be found! (android)
* ERR_GENERAL ... A unspecific error. Check the logs to see want exactly happened. (web, android, ios)


## Platform: Web/PWA

This implementation just opens a browser window to let users enter their credentials.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,9 @@
import com.getcapacitor.PluginCall;
import org.json.JSONObject;

import java.util.HashMap;
import java.util.Iterator;
import java.util.Map;
import java.util.Random;

/**
Expand All @@ -28,7 +31,7 @@ public static <T> T getCallParam(Class<T> clazz, PluginCall call, String key, T
if (clazz.isAssignableFrom(String.class)) {
value = o.getString(k);
} else if (clazz.isAssignableFrom(Boolean.class)) {
value = o.getBoolean(k);
value = o.optBoolean(k);
} else if (clazz.isAssignableFrom(Double.class)) {
value = o.getDouble(k);
} else if (clazz.isAssignableFrom(Integer.class)) {
Expand All @@ -49,6 +52,31 @@ public static <T> T getCallParam(Class<T> clazz, PluginCall call, String key, T
return defaultValue;
}

public static Map<String, String> getCallParamMap(PluginCall call, String key) {
Map<String, String> map = new HashMap<>();
String k = getDeepestKey(key);
try {
JSONObject o = getDeepestObject(call.getData(), key);
JSONObject jsonObject = o.getJSONObject(k);
if (jsonObject != null) {
Iterator<String> keys = jsonObject.keys();
if (keys != null) {
while (keys.hasNext()) {
String mapKey = keys.next();
if (mapKey != null && mapKey.trim().length() > 0) {
String mapValue = jsonObject.getString(mapKey);
if (mapValue != null && mapValue.trim().length() > 0) {
map.put(mapKey, mapValue);
}
}
}
}

}
} catch (Exception ignore) {}
return map;
}

public static String getDeepestKey(String key) {
String[] parts = key.split("\\.");
if (parts.length > 0) {
Expand Down
Loading

0 comments on commit 2023ab2

Please sign in to comment.