Skip to content

Instantly share code, notes, and snippets.

View lapinek's full-sized avatar

Konstantin Lapine lapinek

View GitHub Profile
// Building authorization request.
let request = OIDAuthorizationRequest(
configuration: configuration,
clientId: clientId,
clientSecret: nil,
scopes: scopes,
redirectURL: redirectURI,
responseType: OIDResponseTypeCode,
additionalParameters: ["acr_values": "persistent-cookie"]
)
// . . .
let externalUserAgent = OIDExternalUserAgentIOSSafari(presentingViewController: self)
appDelegate.currentAuthorizationFlow = OIDAuthorizationService.present(request, externalUserAgent: externalUserAgent) {
response, error in
// . . .
makeTokenRequest()
// . . .
if #available(iOS 11.0, *) {
let externalUserAgent = OIDExternalUserAgentIOSSafari(presentingViewController: self)
appDelegate.currentAuthorizationFlow = OIDAuthState.authState(byPresenting: request, externalUserAgent: externalUserAgent) {
authState, error in
completion(authState, error)
}
// OIDExternalUserAgentIOSSafari.swift
// . . .
if #available(iOS 10.0, *) {
openedSafari = UIApplication.shared.canOpenURL(requestURL!)
UIApplication.shared.open(requestURL!, options: [:], completionHandler: nil)
} else {
openedSafari = UIApplication.shared.openURL(requestURL!)
@lapinek
lapinek / am_oauth2_pkce_access_token.bash
Last active September 4, 2018 18:09
AM 6.0 OAuth 2.0 public "pkce" client requesting access token with cURL
authz_code=$(curl -s -w "%{redirect_url}" 'http://am-service.sample.svc.cluster.local/openam/oauth2/authorize?response_type=code&client_id=pkce&redirect_uri=http://localhost:9999&scope=openid&code_challenge=code_verifier' \
-H 'Cookie: iPlanetDirectoryPro='$(curl -s 'http://am-service.sample.svc.cluster.local/openam/json/realms/root/authenticate' \
-X POST \
-H 'X-OpenAM-Username:amadmin' \
-H 'X-OpenAM-Password:password' \
| sed -e 's/^.*"tokenId":"\([^"]*\)".*$/\1/') \
| sed 's/^.*?code=\([^&]*\).*$/\1/') \
&& curl 'http://am-service.sample.svc.cluster.local:80/openam/oauth2/access_token' \
-X POST \
--data 'client_id=pkce&redirect_uri=http://localhost:9999&grant_type=authorization_code&code='$authz_code \
@lapinek
lapinek / am_oauth2_pkce_client.bash
Last active September 4, 2018 18:07
AM 6.0 OAuth 2.0 public "pkce" client with cURL
curl 'http://am-service.sample.svc.cluster.local/openam/json/realms/root/realm-config/agents/OAuth2Client/pkce' \
-X PUT \
--data '{
"clientType": "Public",
"redirectionUris": ["http://localhost:9999"],
"scopes": ["openid"],
"responseTypes": ["code"],
"tokenEndpointAuthMethod": "client_secret_post",
"isConsentImplied": true,
"postLogoutRedirectUri": ["http://localhost:9999"]